【发布时间】:2015-11-10 01:07:22
【问题描述】:
我正在使用 .NET 应用程序,它通过表单界面创建 SharePoint 列表项。应用程序需要允许用户将附件上传到列表项。我可以创建列表项,但是在使用 list.asmx 服务 addAttachment 方法时,尝试通过 FileUpload 控件附加文件时出现“尝试使用已不存在的对象”错误,文件存储在会话作为字节数组。
我的代码看起来像这样...
创建列表项:
protected void CreateListIteminSharepoint()
{
try
{
ServiceReference1.ListsSoapClient proxy = new ServiceReference1.ListsSoapClient();
proxy.ClientCredentials.Windows.ClientCredential = new NetworkCredential();
XElement list = proxy.GetList("MyList");
// assigning field values...
string strBatch = "<Method ID='1' Cmd='New'><Field Name='ID' >New</Field>
// field assignments omitted to shorten code paste
StringReader reader = new StringReader(strBatch);
XElement method = XElement.Load(reader);
XElement element = new XElement("Batch");
element.SetAttributeValue("OnError", "Continue");
element.SetAttributeValue("PreCalc", "TRUE");
element.SetAttributeValue("ListVersion", "1");
element.SetAttributeValue("ViewName", listViewGuid);
element.Add(method);
XElement ndReturn = proxy.UpdateListItems("MyList", element);
// post headshot image attachment - function in code further down the post
if (Session["Headshot"] != null)
{
var headshotFile = (byte[])Session["Headshot"];
UploadDocToSharepoint(headshotFile, (string)Session["HeadshotFileName"]);
}
}
catch (Exception ex)
{
throw;
}
}
FileUpload 控制按钮事件:
protected void btnHeadShotUpload_Click(object sender, EventArgs e)
{
if (HeadshotUpload.HasFile)
{
var file = HeadshotUpload.FileBytes;
Session.Add("Headshot", file);
Session.Add("HeadshotFileName", headshotFileName + " - " + HeadshotUpload.FileName);
}
}
附件功能:
public void UploadDocToSharepoint(byte[] sourceFile, string destinationFileName)
{
ServiceReference1.ListsSoapClient proxy = new ServiceReference1.ListsSoapClient();
proxy.ClientCredentials.Windows.ClientCredential = new NetworkCredential();
try
{
string addAttach = proxy.AddAttachment("MyList", "3228",
"image.jpg", sourceFile);
MessageBox.Show(addAttach);
}
catch (System.Web.Services.Protocols.SoapException ex)
{
throw;
}
catch (Exception ex)
{
throw;
}
}
ULS 登录 SharePoint Server:
SOAP 异常:Microsoft.SharePoint.SPException:尝试使用 已不复存在的对象。 (来自 HRESULT 的异常:0x80030102 (STG_E_REVERTED)) ---> System.Runtime.InteropServices.COMException (0x80030102):尝试使用已不复存在的对象。 (来自 HRESULT 的异常:0x80030102 (STG_E_REVERTED))
在附件函数中,3228 列表项 ID 是我用于测试的现有列表项。我已验证此列表项确实存在于 SharePoint 列表中。所需的最终结果是将文件附加到在上传附件之前创建的列表项。
任何人都可以提供有关可能导致此错误的原因的任何见解吗?
【问题讨论】:
标签: .net web-services sharepoint sharepoint-2010