locked
how to display sharepoint DocumentLibrary files details into datagridview of windows forms application? RRS feed

  • Question

  • HI!

    Now iam using sharepoint server 2007, here DocumentLibrary is having some files.

    i need to display these files information into datagridview of windows forms application.

    where datagridview columns are like

    type        name (file name)   modified (date)        modifiedby     checked out to

     

    i have the code like...

     

     

    private void button1_Click(object sender, EventArgs e)

    {

     

     

     

     

    using (SPSite oSite1 = new SPSite("http://abcd:39050"))

    {

     

     

    using (SPWeb oWebsite2 = oSite1.OpenWeb("/"))

    {

     

     

    SPDocumentLibrary docLib1 = (SPDocumentLibrary)oWebsite2.Lists["DLIP"];

     

     

    SPListItemCollection items1 = docLib1.Items;

     

     

    foreach (SPListItem item in items1)

    {

    // here code is required...........,please suggest me................

     

     

    }

    }

     

    A GREAT THANKS FOR YOUR PARICIPATION....

    PLEASE REPLAY ME...

    Monday, October 4, 2010 12:27 PM

Answers

  • Because you are using SharePoint 2007, here is one important information.

    Please note that your code will work only on SharePoint server where sharepoint is installed. However if you want your windows application to run on a client machine to access sharepoint remotely, You will have to use SharePoint Web services Or put your above code in a custom web service and deploy on sharepoint server. The point is that you need to work with webservices in order to perform this from a client machine to access sharepoint remotely. Here is an article that describe the code with example

    http://sqlblogcasts.com/blogs/drjohn/archive/2007/11/02/Getting-a-list-of-files-from-a-moss-document-library-using-a-SharePoint-web-service.aspx

     

    FYI! SharePoint 2010 comes with a powerful Client object model where you dont have to deal with web services.

    Let me know if you have any question.


    Moonis Tahir MVP, MCPD, MCSD.net, MCTS BizTalk 2006/SQL 2005/SharePoint Server 2007 (Dev & Config)
    • Marked as answer by Porter Wang Tuesday, October 12, 2010 6:23 AM
    Monday, October 4, 2010 2:58 PM

All replies

  • SPListItemCollection items1 = docLib1.Items;

    post this point.

    get the datatable for the list using items1.GetDataTable() . You can use this datatable returned as a source to your datagridview of windows forms application.
     

     

     


    Varun Saxena
    Monday, October 4, 2010 1:03 PM
  • hello

    since you have SPListItem instance you should read its field values. You can use static field names or field guids. For your case you can use OTB class SPBuiltInFieldId class which contains fuild guids you need:

    foreach (SPListItem item in items1)
    {
      var type = item[SPBuiltInFieldId.DocIcon];
      var fileName = item[SPBuiltInFieldId.LinkFilename];
      var modified = item[SPBuiltInFieldId.Modified];
      var modifiedBy = item[SPBuiltInFieldId.Modified_x0020_By];
      var checkoutTo = item[SPBuiltInFieldId.CheckoutUser];
    
      // add items with retrieved values into your grid view in win forms app
      // ...
    }
    
    having field values you the only remaining work - is to add items into your grid view


    Blog - http://sadomovalex.blogspot.com
    Codeplex - http://camlex.codeplex.com
    Monday, October 4, 2010 1:51 PM
  • Because you are using SharePoint 2007, here is one important information.

    Please note that your code will work only on SharePoint server where sharepoint is installed. However if you want your windows application to run on a client machine to access sharepoint remotely, You will have to use SharePoint Web services Or put your above code in a custom web service and deploy on sharepoint server. The point is that you need to work with webservices in order to perform this from a client machine to access sharepoint remotely. Here is an article that describe the code with example

    http://sqlblogcasts.com/blogs/drjohn/archive/2007/11/02/Getting-a-list-of-files-from-a-moss-document-library-using-a-SharePoint-web-service.aspx

     

    FYI! SharePoint 2010 comes with a powerful Client object model where you dont have to deal with web services.

    Let me know if you have any question.


    Moonis Tahir MVP, MCPD, MCSD.net, MCTS BizTalk 2006/SQL 2005/SharePoint Server 2007 (Dev & Config)
    • Marked as answer by Porter Wang Tuesday, October 12, 2010 6:23 AM
    Monday, October 4, 2010 2:58 PM