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:
- 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!
Articles & Research
SharePoint Security
SharePoint Development
SharePoint Architecture
Claims Authentication
Forefront For SharePoint
AIS / Dynamics GP
Team Foundation Server
Pex And Moles
ISA/TMG/IAG/UAG
DPM
Cardspace
Research Methodology
Rural ICT Development
Numerical Analysis
Multi-Level Research
Knowledge Management
Personal/Off-Topic
No Comments
Trackbacks/Pingbacks