在sharepoint库中上载文件会引发未经处理的异常(hresult:0x80020009,错误代码:-2147352567),错误消息为空
我使用以下代码示例在文档库中上载多个文件(使用sharepoint对象模型,无webservice),但有时它会抛出异常hresult:0x80020009,错误代码为-2147352567,并且当文件成功上载到文档库时,错误消息为空(空字符串)。大多数情况下,它只发生在第一次,这意味着它发生在上传第一个文档之后,所有过程都顺利进行。第一次发生后,不会发生异常。如果我吃了这个特例,效果很好。有人能帮我追踪这个问题吗?我不明白为什么文件上传到文档库时会抛出异常。我想知道真正的原因是什么,我应该做些什么来避免这个问题 代码:在sharepoint库中上载文件会引发未经处理的异常(hresult:0x80020009,错误代码:-2147352567),错误消息为空,sharepoint,file,exception,upload,Sharepoint,File,Exception,Upload,我使用以下代码示例在文档库中上载多个文件(使用sharepoint对象模型,无webservice),但有时它会抛出异常hresult:0x80020009,错误代码为-2147352567,并且当文件成功上载到文档库时,错误消息为空(空字符串)。大多数情况下,它只发生在第一次,这意味着它发生在上传第一个文档之后,所有过程都顺利进行。第一次发生后,不会发生异常。如果我吃了这个特例,效果很好。有人能帮我追踪这个问题吗?我不明白为什么文件上传到文档库时会抛出异常。我想知道真正的原因是什么,我应该做些
尝试使用下面提供的代码来帮助您
using (SPSite spsite = new SPSite("http://SPS01"))
{
using (SPWeb spweb = spsite.OpenWeb())
{
spweb.AllowUnsafeUpdates = true;
SPFolder spfolder = spweb.Folders[Site + "/Shared Documents/"];
byte[] content = null;
using (FileStream filestream = new FileStream("C:/Sample.docx", System.IO.FileMode.Open))
{
content = new byte[(int)filestream.Length];
filestream.Read(content, 0, (int)filestream.Length);
filestream.Close();
}
SPFile spfile = spfolder.Files.Add("Sample.docx", content, true);
//Upload file in subfolder.
//SPFile spfile = spfolder.SubFolders["Demonstration Folder"].Files.Add("Sample.docx", content, true);
spfile.Update();
}
}
你能发布完整格式的代码吗?使用(var site=new SPSite(folderUrl))使用(SPWeb=site.RootWeb){SPFolder folder=web.GetFolder(folderUrl);foreach(fileSource.GetFiles()中的文件文件){folder.Files.Add(folderUrl+“/”+fileName,File.Data,true);}我也有同样的问题,阿克斯-有人找到了解决办法吗?仍然面临同样的问题。它在第行抛出异常:spfolder.Files.Add(“Sample.docx”,content,true);捕获到Microsoft.SharePoint.SPException消息=“Source=Microsoft.SharePoint ErrorCode=-2147352567 NativeErrorMessage=FAILED hr detected(hr=0x80020009)检查SPFileCollection的有效性,我猜引发异常是因为您试图调用无效对象上的方法。(spfolder.Files)Ashutosh Singh-我和Alex遇到了同样的问题。如何“检查SPFileCollection的有效性”?我已经查看了SPFileCollection和相关的SPFolder对象属性(在调试器中)-它们在每次文件上载时看起来相同(当然除了文件夹中的文件计数和集合),但SP在第一次上载时抛出异常(本机代码)。
using (SPSite spsite = new SPSite("http://SPS01"))
{
using (SPWeb spweb = spsite.OpenWeb())
{
spweb.AllowUnsafeUpdates = true;
SPFolder spfolder = spweb.Folders[Site + "/Shared Documents/"];
byte[] content = null;
using (FileStream filestream = new FileStream("C:/Sample.docx", System.IO.FileMode.Open))
{
content = new byte[(int)filestream.Length];
filestream.Read(content, 0, (int)filestream.Length);
filestream.Close();
}
SPFile spfile = spfolder.Files.Add("Sample.docx", content, true);
//Upload file in subfolder.
//SPFile spfile = spfolder.SubFolders["Demonstration Folder"].Files.Add("Sample.docx", content, true);
spfile.Update();
}
}