我尝试在文档库中将文件夹添加到自定义文档集。但是有些东西不对一个或多个字段,并且以下错误消息不会向我提供将其缩小的信息。我正在寻找一种方法来识别和修复库中的违规字段。
Microsoft.SharePoint.Client.ServerException was unhandled
HResult=-2146233088
Message=One or more field types are not installed properly. Go to the list settings page to delete these fields.
ServerErrorCode=-2130575340
ServerErrorTraceCorrelationId=0e7a749d-70a8-2000-36cf-14f8618874a2
ServerErrorTypeName=Microsoft.SharePoint.SPException
ServerStackTrace=""
Source=Microsoft.SharePoint.Client.Runtime
StackTrace:
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponseStream(Stream responseStream)
at Microsoft.SharePoint.Client.ClientRequest.ProcessResponse()
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQueryToServer(ChunkStringBuilder sb)
at Microsoft.SharePoint.Client.ClientRequest.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientRuntimeContext.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientContext.ExecuteQuery()
at Microsoft.SharePoint.Client.ClientContextExtensions.ExecuteQueryImplementation(ClientRuntimeContext clientContext, Int32 retryCount, Int32 delay)
at Microsoft.SharePoint.Client.FileFolderExtensions.CreateFolderImplementation(FolderCollection folderCollection, String folderName, Folder parentFolder)
at Microsoft.SharePoint.Client.FileFolderExtensions.CreateFolder(Folder parentFolder, String folderName)
at AddFolderToDocSet.Program.Main(String[] args) in C:\Users\user\Documents\Visual Studio 2015\Projects\PnPCoreTest\AddFolderToDocSet\Program.cs:line 51
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
这是我用来添加利用PNP-Sites-Core library。
的文件夹的代码// Get Root Folders collection for
var projLibRootFldrs = prjLib.RootFolder;
ctx.Load(projLibRootFldrs, pf => pf.Folders);
ctx.ExecuteQueryRetry();
// Get the Document Set
Folder f = projLibRootFldrs.EnsureFolder("Test1");
f.CreateFolder("foo"); // Error here
更新:2016年4月21日
经过艰苦的分析(错误...试验,错误,永远重复)我已将其缩小到"共享列中的字段" "文档集设置"部分当我检查任何错误发生时,似乎。当我取消选中所有字段以便没有共享时,我可以添加该文件夹。
更新:2016年4月26日
以下是用于创建文件夹的确切控制台程序:
static void Main(string[] args)
{
string pwd = System.Environment.GetEnvironmentVariable("SOME_PWD", EnvironmentVariableTarget.User);
if (string.IsNullOrEmpty(pwd))
{
System.Console.Write("MSOPWD user environment variable empty, cannot continue. Press any key to end.");
System.Console.ReadKey();
return;
}
// Get access to source site
using (var ctx = new ClientContext("https://mysite.sharepoint.com/sites/demo3"))
{
//Provide count and pwd for connecting to the source
var passWord = new SecureString();
foreach (char c in pwd.ToCharArray()) passWord.AppendChar(c);
ctx.Credentials = new SharePointOnlineCredentials("me@email.com", passWord);
Web web = ctx.Web;
string docSetLibName = "P1";
string docSetFolderName = "Test1";
string folderName = "Foo1";
try
{
List list = EnsureTargetTestFolder(ctx, docSetLibName);
Folder docSet = EnsureTestDocumentSet(ctx, list, docSetFolderName);
MakeStandardFolder(ctx, docSet, folderName);
}catch(Exception exp)
{
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Black;
Console.WriteLine("ERROR:" + Environment.NewLine);
Console.WriteLine(exp.Message + Environment.NewLine);
Console.WriteLine(Environment.NewLine);
Console.ResetColor();
}
Console.WriteLine("Done...");
}
Console.ReadKey();
}
private static List EnsureTargetTestFolder(ClientContext ctx, string docSetLibName)
{
if (ctx.Web.ListExists(docSetLibName) == false) {
Console.WriteLine(String.Format("List {0} not found... creating new!", docSetLibName));
// Make the list
List newList = ctx.Web.CreateList(ListTemplateType.DocumentLibrary, docSetLibName, false, true, "", true);
newList.AddContentTypeToListByName("DocSetTest");
newList.RemoveContentTypeByName("Document");
newList.EnableFolderCreation = true;
return newList;
}else
{
Console.WriteLine(String.Format("List {0} exists!", docSetLibName));
return ctx.Web.GetListByTitle(docSetLibName);
}
}
private static Folder EnsureTestDocumentSet(ClientContext ctx, List list, string docSetLibName)
{
if (list.RootFolder.FolderExists(docSetLibName) == false)
{
Console.WriteLine(String.Format("Document Set '{0}'does not exist... creating new!", docSetLibName));
Folder fldr = list.RootFolder.CreateDocumentSet(docSetLibName, ctx.Web.GetContentTypeByName("DocSetTest").Id);
return fldr;
}else
{
Console.WriteLine(String.Format("Document Set '{0}\\{1}' exists", list.EntityTypeName, docSetLibName));
return list.RootFolder.ResolveSubFolder(docSetLibName);
}
}
private static void MakeStandardFolder(ClientContext ctx, Folder docSet, string folderName)
{
if (docSet.FolderExists(folderName) == false)
{
Console.WriteLine(String.Format("Folder {0} does not exist ... creating new!", folderName));
docSet.CreateFolder(folderName);
}else
{
Console.WriteLine(String.Format("Folder {0} already exists", folderName));
}
}
答案 0 :(得分:1)
我已经测试了您提供的步骤。是的,您的步骤发生错误。 我注意到" DocSetTest ID"列可能会导致错误:
1.create" DocumentSetName ID"列并使其共享,发生错误。
2.创建" ID"列并使其共享,发生错误。
3.create" DocumentSetName_ID"列并使其共享,它工作正常。
4.create" IDDocumentSetName"列并使其共享,它工作正常。
所以也许你的" ID"或" DocumentSetName ID"使用OfficeDevPnP.Core库时,列可能会冲突(可能存在" ID"列)。尝试更改列的名称并检查结果。
答案 1 :(得分:0)
使这项工作的诀窍是首先访问并删除DocumentSetTemplate的SharedFields集合中的字段,然后创建该文件夹,然后恢复SharedFields。以下是用于执行此操作的方法。
private static void HideSharedFields(ClientContext ctx, ContentType ct, out SharedFieldCollection unsharedFields)
{
DocumentSetTemplate docSetTemplate = DocumentSetTemplate.GetDocumentSetTemplate(ctx, ct);
SharedFieldCollection sharedFields = docSetTemplate.SharedFields;
unsharedFields = sharedFields;
ctx.Load(sharedFields);
ctx.ExecuteQueryRetry();
foreach(var fld in sharedFields)
{
Console.WriteLine(String.Format(" - Removing SharedField '{0}'", fld.Title));
docSetTemplate.SharedFields.Remove(fld);
fld.UpdateAndPushChanges(true);
}
docSetTemplate.Update(true);
ctx.ExecuteQueryRetry();
}
private static void RevealSharedFields(ClientContext ctx, ContentType ct, SharedFieldCollection unsharedFields)
{
DocumentSetTemplate docSetTemplate = DocumentSetTemplate.GetDocumentSetTemplate(ctx, ct);
foreach (var fld in unsharedFields)
{
Console.WriteLine(String.Format(" + Adding SharedField '{0}'", fld.Title));
docSetTemplate.SharedFields.Add(fld);
fld.UpdateAndPushChanges(true);
}
docSetTemplate.Update(true);
ctx.ExecuteQueryRetry();
}