Friday, March 18, 2011

sharepoint list data to excel, programatically

thanks to the author,

http://avinashkt.blogspot.com/2009/05/programmatically-export-records-from.html

here is the trick

string spListName = "CartDetails";
SPList oList = SPContext.Current.Web.Lists[spListName];
string listGUID = oList.ID.ToString().ToUpper().Replace("-", "\u00252D");
string viewGUID = oList.DefaultView.ID.ToString().ToUpper().Replace("-", "\u00252D");
strCommand = "javascript:EnsureSSImporter();" +
"javaScript:ExportList('\u002f_vti_bin\u002fowssvr.dll?CS=65001\u0026"
+ "Using=_layouts\u002fquery.iqy\u0026" + "List=\u00257B"
+ listGUID + "\u00257D\u0026" + "View=\u00257B" + viewGUID
+ "\u00257D\u0026" + "RootFolder=\u00252FLists\u00252F"
+ spListName.Replace("_", "\u00255F") + "\u0026" + "CacheControl=1')";

btnExportToExcel.Attributes.Add("onclick", strCommand+"; return false;");

No comments:

Post a Comment