In this article I am going to
discuss how you can retrieve all the document details from share point Document
library. Here is the sample code
Create Data table Document
details
void CreateDocumenttable(){try{dtDocuments = new DataTable();dtDocuments.Columns.Add("ID", typeof(string));dtDocuments.Columns.Add("Name", typeof(string));dtDocuments.Columns.Add("Title", typeof(string));dtDocuments.Columns.Add("CreatedBy", typeof(string));dtDocuments.Columns.Add("modifiedBy", typeof(string));dtDocuments.Columns.Add("CreatedAt", typeof(string));dtDocuments.Columns.Add("LastmodifiedAt", typeof(string));dtDocuments.Columns.Add("Type", typeof(string));}catch (Exception){throw;}}
Read Document details
void GetDocuments(string LibraryName){this.Cursor = Cursors.WaitCursor;try{CreateDoctable();SPSite currentSite = new SPSite(URL);using (SPWeb web = currentSite.OpenWeb()){SPList list1 = web.Lists[LibraryName];SPListCollection listcollection = web.Lists;SPQuery myquery = new SPQuery();myquery.Query = "";SPListItemCollection ItemCollection = list1.GetItems(myquery);foreach (SPItem item in ItemCollection){DataRow dr = dtDocuments.NewRow();dr["ID"] = item.ID;if (item["Title"]!=null)dr["Title"] = item["Title"];dr["Name"] = item["Name"];dr["LastmodifiedAt"] = item["Modified"];dr["Type"] = item["ContentType"];dr["CreatedAt"] = item["Created"];if (item["Modified By"]!=null){SPFieldUserValue userValue = new SPFieldUserValue(web, item["Modified By"].ToString());SPUser userObject = userValue.User;dr["modifiedBy"] = userObject.Name;}if (item["Created By"] != null){SPFieldUserValue userValue = new SPFieldUserValue(web, item["Created By"].ToString());SPUser userObject = userValue.User;dr["CreatedBy"] = userObject.Name;}dtDocuments.Rows.Add(dr);}}}catch (Exception){this.Cursor = Cursors.Default;return;}this.Cursor = Cursors.Default;}
No comments:
Post a Comment