Another question was asked in the newsgroups about how to get access to an SPFile object, and once that is object is harnessed, how to open the file in a binary read.
In order to go this, you should setup a new method that is taking a string parameter which will lead to the SPFile object. Decorate your method with public byte[] GetFileContent(string [parameter you want to name for the path to your file])
This will be used in the first part of the method when you getting a hold of the SPFile object:
-
SPFile oFile = oWeb.GetFile([parameter representing path to your file]);
Once you have referenced that file, it is a good practice to test whether the file exists:
-
if (oFile.Exists)
Then if it doesn't fart at this point, complete the return to open the file in binary format:
-
if (oFile.Exists)
-
{
-
return oFile.OpenBinary();
-
}
Then componesate for the if/else statement, by completing the method as such:
-
else
-
{
-
return ((byte[]) null);
-
}
That should do the trick!











July 22nd, 2007 at 5:28 pm
[...] How To Open An SPFile To Access Content [...]