how to read files from document library
Windows Server Forum Index Windows Server
Server discussion on Windows platform.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web winserverhelp.com
how to read files from document library

 
Post new topic   Reply to topic    Windows Server Forum Index -> Portal Server Development
Author Message
ashish
Guest





Posted: Tue Jan 11, 2005 3:03 pm    Post subject: how to read files from document library Reply with quote

hi
how do i read contents of files present in a document library. the library
is supposed to contain excel files.

thnx
Back to top
Jim McCusker
Guest





Posted: Sun Jan 16, 2005 5:51 am    Post subject: RE: how to read files from document library Reply with quote

You simply need to get an SPFile object for the file you wish to read and use
the .LoadBinary() method to get a byte[] of the files contents.

You can get the file by creating an SPWeb object from a SPSite object:

SPWeb myWeb = new SPSite(urlSite).OpenWeb();

then get the file using the .GetFile() method:

SPFile myFile = myWeb.GetFile(filePath);

Now that you have the file, you can read the contents using the OpenBinary()

byte[] fileContents = myFile.OpenBinary();

Also, if you want the file contents in a string, you can use the SPWeb
method .GetFileAsString():

string fileContents = myWeb.GetFileAsString(filePath);

That's about it...

--Jim


"ashish" wrote:

Quote:
hi
how do i read contents of files present in a document library. the library
is supposed to contain excel files.

thnx
Back to top
 
Post new topic   Reply to topic    Windows Server Forum Index -> Portal Server Development All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




New Topics Powered by phpBB