kevin
kevin

Reputation: 14095

SharePointWeb.GetFile method gave me "Cannot open file" SPException

I try to open a file like that

fromServerURL = http://mysite.com/sites/CM

, it is OK.

but it gave me the error when i pass the value like

fromServerURL = http://mySite.com/

SPFile file = oWebsiteFrom.GetFile(fromServerURL + "/" + fromPath + "/" + fileName);

I try to test it and see those.

long length = file .Length; - > it gives me the correct length
byte[] a= file .OpenBinary(); - > it gave me the error
file.Item is also null.

I found this link to solve the issue but it's suited for my situation when I'll not know the exact the folder structure.

http://blogs.msdn.com/b/momalek/archive/2011/02/28/reading-item-attachments-programmatically-spfile-openbinary-exception.aspx

Upvotes: 0

Views: 1188

Answers (1)

Tjassens
Tjassens

Reputation: 922

A better description of your problem would help improve the quality of the answers but ill give it a try:

Instead of getting the file like you're doing now just get the listitem and then get the file from the listitem:

SPListItem.File

This way you won't have to construct the file url like you're doing now and you can get the listitem by using Linq/Linq2SharePoint/caml...

Upvotes: 1

Related Questions