We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

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);
                          file.Update();
                  }
 
                  docLibrary.Update();
 
                  oSPWeb.AllowUnsafeUpdates = false;
          }
 
          objSite.AllowUnsafeUpdates = false;
                  
 }

 
 


Related Tags:

SharePoint

Author: Premananda Das

top

Related Pages

  • SharePoint Consulting Gurus
  • SharePoint Development Projects

SharePoint

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login