TODO:
Have you ever wanted detailed errors to be returned from your Sharepoint Application Pages? Selecting "Detailed Errors" in IIS will not do it alone. In addition, you need to do the additional step below.
SOLUTION:
Open the web.config at "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\web.config"
Change <customErrors mode="On" /> to <customErrors mode="Off" /> under the system.web node
NOTES:
There are no notes on this topic
TODO:
Have you ever had data from Sharepoint display as for instance '&' rather than '&'
SOLUTION:
The solution is simple, just escape the XSL Parameter as follows:
<xsl:value-of select="@MyDataParam" disable-output-escaping="yes" />
NOTES:
There are no notes on this topic.
TODO:
Have you ever received the dreaded 'Recycle IIS Application Pool: Provider load failure' message when trying to deploy and run a Sharepoint Solution from Visual Studio? No need to reboot, just put the following lines in a .bat file, and run it as Administrator.
SOLUTION:
net stop SPTimerV4
net start SPTimerV4
net stop SPUserCodeV4
net start SPUserCodeV4
net stop SPAdminV4
net start SPAdminV4
REM net stop TrustedInstaller
REM net start TrustedInstaller
REM net stop Winmgmt
REM net start Winmgmt
REM net stop W3SVC
REM net start W3SVC
iisreset
NOTES:
If that does not work, try removing the REM statements, and it should work..
TODO:
Have you ever wanted to add a file, as an attachment to a new item in a SharePoint list?
SOLUTION:
/// <summary>Add the contents of a file to a document library</summary>
/// <param name="DocumentData">byte[] of the document data</param>
/// <param name="SharePointUrl">The URL to the sharepoint server</param>
/// <param name="SharePointSite">The name of the site the document library resides</param>
/// <param name="DocumentLibrary">The name of the document library</param>
/// <param name="MetaData">Any meta data you want to add. For instance if there are other columns, you can specify them here.</param>
/// <param name="OverWriteFile">Overwrite flag. true or false, self explanatory</param>
/// <returns></returns>
public bool AddFileToList(byte[] DocumentData, string SharePointUrl, string SharePointSite, string List, Hashtable MetaData)
{
try
{
//get the site
using (SPSite mysiteCollection = new SPSite(SharePointUrl))
{
// Alternately you can use oSite.RootWeb if you want to access the main site
// but we will just do a find so we do not need to worry about levels
SPWebInfo webinfo = mysiteCollection.AllWebs.WebsInfo.Find(delegate(SPWebInfo w) { return w.Title.ToUpper() == SharePointSite.ToUpper(); });
//get the site by title (need to because name could be site/site...)
using (SPWeb rootSite = mysiteCollection.AllWebs[webinfo.Id]) //now get the web by GUID
{
SPList incompleteList = rootSite.Lists[List]; //the list by display name
SPListItem newItem = incompleteList.Items.Add(); //get the item from the file just uploaded
//now add each item to the properties
if (MetaData != null)
{
//take each piece of meta data, and apply it to the item
foreach (object key in MetaData.Keys)
{
//newItem.Properties.Add(key, MetaData[key]);
newItem[key.ToString()] = MetaData[key];
}
}
newItem.Attachments.Add(string.Format("{0}.xml", Guid.NewGuid()), DocumentData); //add attachments to the list item
newItem.Update(); //update the item
}
}
return true;
}
catch (Exception x)
{
return false;
}
}
NOTES:
The meta data are columns on the item. You can populate those during the add, by passing them in in a Hashtable.
TODO:
Have you ever wanted to add a document to a SharePoint document library? The below example, is a method that will allow you to do just that.
SOLUTION:
/// <summary>
/// Add the contents of a file to a document library
/// </summary>
/// <param name="DocumentData">byte[] of the document data</param>
/// <param name="SharePointUrl">The URL to the sharepoint server</param>
/// <param name="SharePointSite">The name of the site the document library resides</param>
/// <param name="DocumentLibrary">The name of the document library</param>
/// <param name="MetaData">Any meta data you want to add. For instance if there are other columns, you can specify them here.</param>
/// <param name="OverWriteFile">Overwrite flag. true or false, self explanatory</param>
/// <returns></returns>
public bool AddFileToDocumentLibrary(byte[] DocumentData, string SharePointUrl, string SharePointSite, string DocumentLibrary, Hashtable MetaData, bool OverWriteFile)
{
try
{
//get the site
using (SPSite mysiteCollection = new SPSite(SharePointUrl))
{
//get web info by title (i need to do it this way)
SPWebInfo webinfo = mysiteCollection.AllWebs.WebsInfo.Find(delegate(SPWebInfo w) { return w.Title.ToUpper() == SharePointSite.ToUpper(); });
//get the site by title (need to because name could be site/site...)
using (SPWeb rootSite = mysiteCollection.AllWebs[webinfo.Id]) //now get the web by GUID
{
SPFile newFile = null;
SPFolder incompleteLibrary = rootSite.Folders[DocumentLibrary]; //the list by display name
//now create a hash of our fields we want to set, and do it in one shot.
if (MetaData == null || MetaData.Count == 0)
newFile = incompleteLibrary.Files.Add(string.Format("{0}.xml", Guid.NewGuid()), DocumentData, OverWriteFile); //add it to the library
else
newFile = incompleteLibrary.Files.Add(string.Format("{0}.xml", Guid.NewGuid()), DocumentData, MetaData, OverWriteFile); //add it to the library
}
}
return true;
}
catch (Exception x)
{
return false;
}
}
NOTES:
In my case, I was only adding XML files. Therefore you can change the file name generation to use an extension that is passed in potentially.
TODO:
Have you ever had a lookup column, and you want to get its value programatically using C#?
1. I have a column that is called, Task Id.
2. "Task Id" in #1, is a lookup to the "ID" column of a list called "Tasks"
3. I have an event receiver that needs to get the "Task Id" from the form.
SOLUTION:
//my event receiver code....
public override void ItemAdded(SPItemEventProperties properties)
{
SPFieldLookup lookupField = properties.ListItem.Fields["Task ID"] as SPFieldLookup;
SPFieldLookupValue taskIdVal = null;
object obj = properties.ListItem["Task ID"];
if (lookupField != null)
taskIdVal = lookupField.GetFieldValue(obj.ToString()) as SPFieldLookupValue;
string taskId = taskIdVal.LookupValue;
}
NOTES:
There are no notes on this topic.
TODO:
Have you ever had the dreaded "Error occurred in deployment step 'Activate Features': <nativehr>0x80070002</nativehr><nativestack></nativestack>" error when deploying an Event Receiver that targets a specific list?
SOLUTION:
In my case, this was caused by an invalid 'ListURL' setting in my elements.xml file. Be sure the 'Site URL' property of your project points to the site that the List resides. If this is pointed to the level above, the list will not be found, and you will get the error above. ListURL needs to be 'Lists/'{your list name} ex. List/Customers, thus you see why it is important for the Site URL to be set properly.
NOTES:
There are no notes on this topic.
TODO:
I was trying to debug a SharePoint 2007 feature, in Visual Studio 2008, on IIS 7, and was getting the "unable to start debugging on the web server the web server is not configured correctly" error. I seen many posts on this but what worked for me is documented below.
SOLUTION:
Open up you site in IIS.
Right click on the site, and choose Properties.
Click ".Net Compilation"
Under "Behavior", click Debug and set to True.
Now you can debug from Visual Studio
NOTES:
There are no notes on this topic.
TODO:
When you click on the Team Site link in Office 365, it takes you to https://sitename.com/SitePages/Home.aspx. The issue is, that we really want to go to https://sitename.com/site/Intranet/SitePages/Home.aspx.e.aspx.
SOLUTION:
To accomplish this, I added a CEWP to the sitename.com/SitePages/Home.aspx, that has a simple script that redirects to the page I really want to go to.
<script teyp="text/javascript">window.location.href = "https://sitename.com/sites/Intranet/SitePages/Home.aspx";</script>
NOTES:
So now the obvious, how do I ever edit the page again? To do this I used SharePoint Designer. Simply open the site by placing the root url in the location to open input (sitename/SitePages/). From there I can now edit the page and the CEWP.
TODO:
If you have had the error "System.InvalidOperationException: The farm is unavailable.", and the exception printed below, then try the solution below.
Complete Exception:
WebHost failed to process a request.
Sender Information: System.ServiceModel.ServiceHostingEnvironment+HostingManager/33711845
Exception: System.ServiceModel.ServiceActivationException: The service '/1e1dea56eb8c443782ab6f9948b81e0d/ProfilePropertyService.svc' cannot be activated due to an exception during compilation. The exception message is: The farm is unavailable.. ---> System.InvalidOperationException: The farm is unavailable.
at Microsoft.SharePoint.Administration.Claims.SPSecurityTokenServiceManager.get_Local()
SOLUTION:
Open IIS
Go to the App Pool, Right click and choose "Advanced"
Set Enable 32-bit Applications = false
NOTES:
No notes are available for this topic.