I have the chunk of code below:
SPListItem source = //some list item;
foreach (string file in source.Attachments)
{
SPFile oFile = source.Web.GetFile(file);
string strFilename = oFile.Name;
byte[] binFile = oFile.OpenBinary(); //Errors out here!
destination.Attachments.Add(oFile.Name, binFile);
destination.SystemUpdate();
}
Which throws this error:
EXCEPTION in CrossSiteCopy! Cannot open file "2012-05-21_104000.png". at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) at Microsoft.SharePoint.Library.SPRequest.GetFileAsStream(String bstrUrl, String bstrWebRelativeUrl, Boolean bHonorLevel, Byte iLevel, OpenBinaryFlags grfob, String bstrEtagNotMatch, String& pEtagNew, String& pContentTagNew) at Microsoft.SharePoint.SPFile.GetFileStreamCore(OpenBinaryFlags openOptions, String etagNotMatch, String& etagNew, String& contentTagNew) at Microsoft.SharePoint.SPFile.GetFileStream(OpenBinaryFlags openOptions, String etagNotMatch, String& etagNew, String& contentTagNew) at Microsoft.SharePoint.SPFile.OpenBinary(SPOpenBinaryOptions openOptions) at Copy_Special.CrossSiteCopy.CopyFieldValues(SPListItem source, SPListItem destination) at Copy_Special.CrossSiteCopy.<>c_DisplayClass1.b_0() at Microsoft.SharePoint.SPSecurity.<>c_DisplayClass4.b_2() at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) at Copy_Special.CrossSiteCopy.Execute(ActivityExecutionContext executionContext)
It's not giving me much information about WHY it cannot open the file. Can any one point me to what the problem might be?