Useful WSS 3.0 Samples


In Dublin it’s always raining, so there’s always some time to post a new article. Two useful code snippets for WSS3 developers: 

Smartly export a document from a WSS Document Library:

// Set up the webclient with the correct credentials
WebClient webClient = new System.Net.WebClient();
webClient.Credentials = credential;

// Export the document to the given folder 
webClient.DownloadFile(documentUrl, docFullPath);

Smartly import (upload) a document to a WSS Document Library:

// Set up the webclient with the correct credentials
WebClient webClient = new System.Net.WebClient();
webClient.Credentials = credential;

// Upload the file
webClient.UploadFile(destinationUrl, "PUT", sourceFilePath);

Comments (6)

  1. Daniel says:

    very much off topic, but whats the point of having "pingbacks" from other sits, who have just copied and pasted your content….

    Isnt the whoel idea and concept of WSS/MOSS so you dont have to duplicate information?

    I would post this on the other site also, however they dont allow comments.

    Regards,

    Daniel

  2. Avi says:

    What shd be the destinationURL if my Shared Documents URL is

    http://my_server_name/Shared%20Documents/Forms/AllItems.aspx

    Regards,

    Avi.

  3. Johan says:

    Thank you for the code snippets.

    After the upload of the document, it is in a "checked out" status. Is there a simple way to indicate that the document should be marked as "checked in"?

    Regards,

    Johan.

  4. dszabo says:

    Hey Johan,

    You need to use the object model or MOSS web services to check the document back in. See http://msdn.microsoft.com/en-us/library/lists.lists.checkinfile.aspx for an example!

    Chrs,

    David