Thursday, November 20, 2014

Unable to navigate to SharePoint Hosted App and getting Invalid URL message

Our team had been working on one SharePoint Hosted App for couple of days, one day some team members were getting Invalid URL error after installing App to Developer site. Error message is

Invalid URL: ~appWebUrl/Pages/Default.aspx?SPHostUrl=https%3A%2F%2Fsportsoffice%2Esharepoint%2Ecom&SPLanguage=en%2DUS&SPClientTag=18&SPProductNumber=16%2E0%2E2930%2E1217&SPListItemId=1356&SPListId={A80C0C18-8AA6-4D27-9A2A-9E7556539D94}

We all sat together and tried to recollect what we did in last few days, we were using TFS as source control and everybody were check in their code at the EOD, so we checked version history and found that Package folder and package manifest lines in .csproj where missing in project.

Due to this Visual Studio couldn't build right App package, it missed App WSP in published package.

Just restoring Package folder and .csproj file fixed our issue.

Wednesday, November 5, 2014

Get web part assembly name and type name from SharePoint web part gallery


Today i was trying create to custom webpart preview page as test canvas for site admins. For this i wanted to add webpart on fly.  We need few properties like web part type name and web part assembly name for this.



string webPartTitle = " Content Editor Web Part";
string webPartTypeName = string.Empty;
string webPartAssemblyName = string.Empty;

SPList wpGallery = SPContext.Current.Site.GetCatalog(SPListTemplateType.WebPartCatalog);

SPQuery wpQuery = new SPQuery();

wpQuery.Query = @"<Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" + webPartTitle + "</Value></Eq></Where>";
SPListItemCollection items = wpGallery.GetItems(wpQuery);

if (items != null && items.Count > 0)
{
       webPartTypeName = items[0]["WebPartTypeName"].ToString();
       webPartAssemblyName = items[0]["WebPartAssembly"].ToString();
}

Some other useful properties are below

- WebPartDescription
- WebPartPartImageLarge
- LinkWebPart
- WebPartIcon
- Group
- QuickAddGroups