Мы используем приведенный ниже код для создания папки в SharePoint, используя c #:
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;
}
Используя этот код, мы пытаемся создать папку с именем "1122-test" в папке, например "https://test.sharepoint.com/sites/DevSandbox/test/Shared%20Documents/folderlocation/".
Код отлично работает на локальном компьютере, но дает следующие исключения только на производстве:
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)
Мы делаем что-то не так или есть какая-то конфигурация, которую нам нужно сделать на рабочем сервере.