Monday, July 29, 2013

Not valid state of the object

Error occurred in deployment step 'Activate Features':Operation is not valid due current state of the object.

If you receive this error while developing the "Sandbox" solution in SharePoint 2010 using Visual studio 2010.

The reason will be:
You might have trying to change the Sharepoint's solution type "sandbox to Farm" by setting the attribute in VSS 2010.

or SPUserWorkerProcess not been started on your WFE or error occurred in deployment steps.

To resolve this,

Go to your Solution gallery in the Site collection,if you found the solution deactivate it.

Or
Go back to your Visual studio solution explorer and empty all your features (select all features hit the delete button,it will goes to your right hand side of the feature window.)
Now change the solution type to "Farm or Sandbox". Last but not least, Check your event receiver class and its namespace are correctly referred in "Element.xml".

Or,

trying to call the SPSite/SPWeb class in the feature using SPContext. or trying to access the object thats all ready closed by using "using operator" in feature event receiver.

Sunday, July 21, 2013

Single Key with multiple Values in C#

This a simple assumption work around to find the solution for how to retrieve the multiple values through Single Key. NamedValueCollection class in linq comes in handy for me. Helpful link from MSDN NameValueCollection This was very useful when an Library list having many books authored by different authors Just consider a situation you wanted to send an email notification to each individual authors the ratings received from the readers.For this aggregate all of his book details. You need to group the books by grouping authors.Assumption book details from the MSDN. Download from here Book.xml On click of the Button "ReadXmlRecord" method will be called.Read the XML file as DataTable and iterate all the rows with your entity class to apply NameValueCollection for further sorting and filtering. After grouping the record in SharePoint List.

    public void ReadXmlRecord(object sender, EventArgs e)
        {
            BookWithAuthor objBook = null;
            DataSet ds = new DataSet();
            ds.ReadXml(@"D:\books.xml");
            var BookTab = ds.Tables[0];
            NameValueCollection values = new NameValueCollection();
            foreach (DataRow row in BookTab.Rows)
            {
                objBook  = new BookWithAuthor();
                objBook.Author = row["author"].ToString();
                objBook BookTitle = row["title"].ToString();
                cols.Add(objBook.Author, objBook.BookTitle);
                
            }
            using (SPSite site = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    foreach (String value in values.AllKeys)
                    {
                        SPList list = web.Lists["SiteReminder"];
                        SPListItem item = list.Items.Add();
                        web.AllowUnsafeUpdates = true;
                        item["SiteOwner"] = value;
                        item["SiteDetails"] = values[value];
                        item.Update();
                        web.AllowUnsafeUpdates = true;
                    }
                }
            }
            
        }
Class
public class BookWithAuthor
    {
        public string Author { get; set; }
        public string BookTitle { get; set; }
    }
Before grouping the record in Gridview,

Wednesday, July 10, 2013

Object Instantiation in Javascript

May be its simple post.But its big enough to differentiate the object and variable in javascript.

var someVariable = "Some text";
var someOtherVariable = ["Name1","Name2","Name"];

The above lines are just variable declaration with keyword "var".
In javascript,Object Instantiation also can be done in the same fashion but with curly  open and closed braces {}.

Example:
var mYObject = {
                 Name:"Murugesa Pandian"; 
                 WhoIsHe:function() { return "Working as Programmer";}
                }


Now mYObject is an Object which holds the property or attribute or you may be call "Member" ,Name and method(function) WhoIsHe.

Call it as
document.write(mYObject.Name);
document.write(myObject.WhoIsHe());