" Live as if you were to die tomorrow. Learn as if you were to live forever.. "
- Mahatma Gandhi
In some cases we need to add documents to the doument library programatically, the code snippet below demonstrates how to add a document to the document library .
using (SPSite objSite = new SPSite("urlAddress"))
objSite.AllowUnsafeUpdates = true;
using (SPWeb oSPWeb = objSite.OpenWeb())
oSPWeb.AllowUnsafeUpdates = true;
//Test1 is the document library
SPList docLibrary = oSPWeb.Lists["Test1"];
using (FileStream fs = File.OpenRead(FullPath))
//Name is the name of the file
SPFile file = oSPWeb.Files.Add(oSPWeb.Url.ToString() + "/" + docLibrary.Title.ToString()
+ "/" + Name, fs);
oSPWeb.AllowUnsafeUpdates = false;
objSite.AllowUnsafeUpdates = false;
Mail (will not be published) (required)
Enter Captcha Code *
5 + = seven
Burn Ignorance is a knowledge initiative by Mindfire Solutions
Subscribe to our mailing list to get the updates to your email inbox...