0
は、私はプログラム的に以下SharePoint 2007:プログラムでバイナリファイルをドキュメントライブラリにアップロードする方法
のSharePoint 2007でドキュメントライブラリにアイテムを作成するために、問題が発生したことは、私のコードの断片である、おそらくあなたかもしれない、私のエラーが何であるかを指摘することができ:
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(_url))
{
using (SPWeb web = site.OpenWeb())
{
SPList customList = web.Lists["Test1"];
foreach (SPListItem ltItem in customList.Items)
{
if (ltItem.Attachments != null && ltItem.Attachments.Count > 0)
{
//Get Test1 File Collection
SPFolder folder = web.GetFolder(ltItem.Attachments.UrlPrefix);
SPFileCollection fileColl = folder.Files;
//Get binary data of attachment
SPFile file = ltItem.ParentList.ParentWeb.GetFile(ltItem.Attachments.UrlPrefix + ltItem.Attachments[0]);
byte[] fileData = file.OpenBinary();
//Get Relative URL of attachment destination
string destFile = fileColl.Folder.Url + "/" + file.Name;
web.AllowUnsafeUpdates = true;
//Add attachment into Document Library
SPDocumentLibrary docLib = (SPDocumentLibrary)web.Lists["Test2"];
SPFile file2 = docLib.RootFolder.Files.Add(destFile, fileData, true);
file2.Item.Update();
web.AllowUnsafeUpdates = false;
}
}
}
}
});
私はヒット "オブジェクト参照がオブジェクトのインスタンスに設定されていません "というコードファイル2.Item.Update();
ありがとうございます。