none
Sharepoint 2010 document library importing from excel

    Question

  • I have an excel sheet containing more than 100 rows of data, how can I export these rows into existing sharepoint document library. Is this is possible in sharepoint 2010??
    • Moved by Pengyu Zhao Tuesday, January 31, 2012 1:01 AM SP 2010 issue (From:SharePoint - Excel Services (pre-SharePoint 2010))
    Monday, January 30, 2012 10:46 PM

All replies

  • Have a look at the following and see if it helps.

    http://social.technet.microsoft.com/Forums/en-US/sharepoint2010customization/thread/46738e8f-670c-4841-8dad-eb64aec49d21/

    Here in the code a dataset is getting generated that contains all the records from excel and you can loop through it to create enteries in our library.

    Tuesday, January 31, 2012 2:20 AM
  • Hi Geetanjali,

    Thank you for your quick reply. Could you please provide any link which shows, exporting rows from data table to existing sharepoint document libarary.

     

     

     

    Tuesday, January 31, 2012 10:11 AM
  • Try if it helps

    DataTable recordsDT = "assuming you have data table already generated";
    
    
    foreach(DataRow dr in recordsDT)
    {
         SPListItem item = list.Items.Add()'
         item["FieldName1"] = dr["Field1"];
         item["FieldName2"] = dr["Field2"];
         item.Update();
    }
    

    Hope it gives you some idea

    Tuesday, January 31, 2012 7:25 PM
  • If the fields all line up properly (or you create the appropriate view) I've found that I'm able to literally cut and paste my excel rows into a sharepoint list datasheet view.
    Tuesday, January 31, 2012 8:10 PM
  • Hi,

    We can edit the rows in sharepoint list datasheet view, but what I am trying to do is to add multiple rows into sharepoint document library. This rows are available in excel file(including the file name which need to be uploaded into document library). Is there any way to achieve this?

    Wednesday, February 01, 2012 10:41 AM
  • I guess we can't call "item.Upate()" while adding a new item to document library, we have to use "SPFileCollection.Add()" method, if I am wrong please correct me. Could you please provide some code for adding a new item to document library(from code behind [c#]). The whole row deatils are stored with in a datatable.Iterating through this datatable, we need to add each item into existing document library.

     

     

    Wednesday, February 01, 2012 12:40 PM
  • Hi,

         Go to the library dataview provided you should have the required prerequisite installed and copy the data (or row value) from the Excel and paste it in the column that you want.

     

    Please let me know if it helps!!!


    Ajeet
    Wednesday, February 01, 2012 1:04 PM
  • Hi,
     
    The datasheet view of document library is not allowing me to add a new row, but I can edit the existing column values. What I want to do is to add some new rows to existing document library.
     
    using (SPSite site = new SPSite(currSite.Url))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        foreach (DataRow dr in dt.Rows)
                        {
                            string docName = dr["Name"].ToString();
                            using (FileStream fs = (new FileInfo(filePath + docName)).OpenRead())
                            {
                                string fileName = Path.GetFileName(docName);
                                string fileExtension = Path.GetExtension(docName);
    
                                SPList list = web.Lists[listName];
    
                                //add metadata
                                Hashtable ht = new Hashtable();
                                ht.Add("Type", fileExtension);                            
                                SPFile destfile = list.RootFolder.Files.Add(fileName, fs, ht, true);
                                destfile.CheckIn("Copied!");
                            }
                        }
                    }
                }
    I have tried to do it with the above code, but when I try to connect to my web application I am getting error like :
    "The Web application at "http://"  could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application."
    Could you please help me to resolve this issue. Just to let you know that I am using form authentication in my web application.
    Wednesday, February 01, 2012 4:34 PM
  • Hi Kersten,

    try this for SPSite and SPWeb object.

                SPSite site = SPContext.Current.Site;
                SPWeb web = site.OpenWeb(site.Url);


    Please let me know if my post was helpful.
    Wednesday, February 01, 2012 5:34 PM
  • Hi,

         What is the error you are encountering while adding the row in datasheet view? In most scenarios the document library has a column that is mandatory and will not be in the datasheet view (probably Name column). Go to the view settings deselect the columns from the view for which you are not entering the data click ok come to the library go to the datasheet view and try to enter the value.

    Please let me know if it helps!!!


    Ajeet
    Wednesday, February 01, 2012 6:28 PM
  • Hi Murugesa,

    using (SPSite site = new SPSite(currSite.Url))
    using (SPWeb web = site.OpenWeb())

    This code worked when I tested in my local machine with test site. But when I tried to connect to my web applciation url by replacing "currSite.Url" with the "Webapplication url"(example http://www.xxxxx.com) I was getting error like,

     "The Web application at "http://" could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application."

     

    Hi Ajeet,

    I was not getting any error, the new row link was disabled in datasheet view and I was not able to add any rows.

     

     

    Wednesday, February 01, 2012 7:47 PM