Jump to content

SharePoint: Copy Attachments using GetFile


Der letzte Beitrag zu diesem Thema ist mehr als 180 Tage alt. Bitte erstelle einen neuen Beitrag zu Deiner Anfrage!

Empfohlene Beiträge

Geschrieben

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 ...

 

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

 

... 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?

Der letzte Beitrag zu diesem Thema ist mehr als 180 Tage alt. Bitte erstelle einen neuen Beitrag zu Deiner Anfrage!

Erstelle ein Benutzerkonto oder melde dich an, um zu kommentieren

Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde dich hier an.

Jetzt anmelden
×
×
  • Neu erstellen...