kamagra how much to take

How To Open An SPFile To Access Content

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:

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

  1. if (oFile.Exists)

Then if it doesn’t fart at this point, complete the return to open the file in binary format:

  1. if (oFile.Exists)
  2. {
  3. return oFile.OpenBinary();
  4. }

Then componesate for the if/else statement, by completing the method as such:

  1. else
  2. {
  3. return ((byte[]) null);
  4. }

That should do the trick!


No Comments


  1. Links (7/22/2007) « Steve Pietrek’s SharePoint Stuff - [...] How To Open An SPFile To Access Content [...]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>