juergenbauer
Programmer
Hi everyone,
developing a Web Part that is copying an entry from a list to another list (both Issue Lists) I currently faced to a problem:
I have two list items - one is a already existing issue (the 'currentItem'), the other one is a new entry (the 'newRequestItem') to be created in an other list.
I already copied the field values and now i would like to get the attachments as well.
... some code ...
... some more code ...
As described under the 'SPWeb'-class in the SDK-Reference the public method 'GetFile' should return the file object (SPFile) located at the URL specified in the provided parameter string. However, the hard I try no SPFile is returned. Is there something wrong with my code or is there a mistake in the SDK?
developing a Web Part that is copying an entry from a list to another list (both Issue Lists) I currently faced to a problem:
I have two list items - one is a already existing issue (the 'currentItem'), the other one is a new entry (the 'newRequestItem') to be created in an other list.
I already copied the field values and now i would like to get the attachments as well.
... some code ...
Code:
SPAttachmentCollection currentAttachments = currentItem.Attachments;
SPAttachmentCollection newRequestAttachments = newRequestItem.Attachments;
int nofAttachments = currentAttachments.Count;
output.Write(SPEncode.HtmlEncode("nofAttachments: "+ nofAttachments) + "<BR>"); // number of attachments is correctly dispayed
string urlString = currentAttachments.UrlPrefix;
output.Write(SPEncode.HtmlEncode("attachment URL: "+ urlString) + "<BR>"); // the URL is also correctly dispayed
string fileName;
string fileUrl;
for (int p = 0; p < nofAttachments; p++)
{
fileName = currentAttachments[p];
fileUrl = currentAttachments.UrlPrefix + fileName;
output.Write(SPEncode.HtmlEncode("File to get: "+ fileUrl) + "<BR>"); // the URL+Filename is correctly dispayed
string attachFileString = changeRequestSite.GetFileAsString(fileUrl);
output.Write(SPEncode.HtmlEncode("String from File: "+ attachFileString) + "<BR>"); // no problem to get the content of the file
SPFile attachFile = changeRequestSite.GetFile(fileUrl); // ERROR: Value does not fall within the expected range.
byte[] binFile = attachFile.OpenBinary(); // code not executed
newRequestAttachments.Add(fileName, binFile); // code not executed
}
newRequestItem.Update(); // code not executed
As described under the 'SPWeb'-class in the SDK-Reference the public method 'GetFile' should return the file object (SPFile) located at the URL specified in the provided parameter string. However, the hard I try no SPFile is returned. Is there something wrong with my code or is there a mistake in the SDK?