我们正在使用以下代码使用c#在SharePoint中创建文件夹:
private static bool CreateFolder(ClientContext context, string newFolderLocation, string listName, string relativePath, string newFolderName)
{
bool folderCreated = false;
try
{
Web web = context.Web;
List list = web.Lists.GetByTitle(listName);
ListItemCreationInformation newItem = new ListItemCreationInformation();
newItem.UnderlyingObjectType = FileSystemObjectType.Folder;
newItem.FolderUrl = newFolderLocation;
if (!relativePath.Equals(string.Empty))
{
newItem.FolderUrl += relativePath + "/";
}
LogHelper.LogInfo(newItem.FolderUrl+","+ newFolderName);
//Check if Folder exists in SharePoint.
bool folderExists = CheckIfFolderExists(context, list, newItem.FolderUrl, newFolderName);
//Create the folder in SharePoint if does not exist.
if (!folderExists)
{
LogHelper.LogInfo("folder exists:" + folderExists);
newItem.LeafName = newFolderName;
Microsoft.SharePoint.Client.ListItem item = list.AddItem(newItem);
item["Author"] = 9;
item["Editor"] = 9;
item.Update();
context.ExecuteQuery();
}
folderCreated = true;
}
catch (Exception ex)
{
LogHelper.ErrorLogging(ex);
}
return folderCreated;
}
使用此代码,我们试图在文件夹位置“ https://test.sharepoint.com/sites/DevSandbox/test/Shared%20Documents/folderlocation/”中创建一个名为“ 1122-test”的文件夹。
代码在本地计算机上工作正常,但仅在生产环境中会给出以下异常:
Error Message: Reference to undeclared entity 'nbsp'. Line 86, position 111.
Stack Trace: at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.HandleGeneralEntityReference(String name, Boolean isInAttributeValue, Boolean pushFakeEntityIfNullResolver, Int32 entityStartLinePos)
at System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean isInAttributeValue, EntityExpandType expandType, Int32& charRefEndPos)
at System.Xml.XmlTextReaderImpl.ParseText(Int32& startPos, Int32& endPos, Int32& outOrChars)
at System.Xml.XmlTextReaderImpl.ParseText()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)
at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r, LoadOptions o)
at System.Xml.Linq.XDocument.Load(XmlReader reader, LoadOptions options)
at Microsoft.SharePoint.Client.Idcrl.IdcrlAuth.DoGet(String url)
at Microsoft.SharePoint.Client.Idcrl.IdcrlAuth.RequestFederationProviderInfo(String domainname)
at Microsoft.SharePoint.Client.Idcrl.IdcrlAuth.GetFederationProviderInfo(String domainname)
at Microsoft.SharePoint.Client.Idcrl.IdcrlAuth.InitFederationProviderInfoForUser(String username)
at Microsoft.SharePoint.Client.Idcrl.IdcrlAuth.GetServiceToken(String username, String password, String serviceTarget, String servicePolicy)
at Microsoft.SharePoint.Client.Idcrl.SharePointOnlineAuthenticationProvider.GetAuthenticationCookie(Uri url, String username, SecureString password, Boolean alwaysThrowOnFailure, EventHandler`1 executingWebRequest)
at Microsoft.SharePoint.Client.SharePointOnlineCredentials.GetAuthenticationCookie(Uri url, Boolean refresh, Boolean alwaysThrowOnFailure)
at Microsoft.SharePoint.Client.ClientRuntimeContext.SetupRequestCredential(ClientRuntimeContext context, HttpWebRequest request)
at Microsoft.SharePoint.Client.SPWebRequestExecutor.GetRequestStream()
at Microsoft.SharePoint.Client.ClientContext.GetFormDigestInfoPrivate()
at Microsoft.SharePoint.Client.ClientContext.EnsureFormDigest()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at CovantaWebForms.Classes.Helpers.SharePointHelper.CreateFolder(ClientContext context, String newFolderLocation, String listName, String relativePath, String newFolderName)
我们是在做错什么,还是在生产服务器中需要做任何配置?