I have written code where it will show the Sharepoint document library in sp grid view.
In the grid view it will show the doc icon Image correctly. Now i want to Download the uploade document from this when clicked on Doc icon.
Here is the code and Out put of the Image
SPGridView gv = new SPGridView();
gv.ID = "gv";
gv.EmptyDataText = "No items found!";
gv.AllowSorting = true;
gv.AllowFiltering = true;
gv.AutoGenerateColumns = false;
gv.EnableSortingAndPagingCallbacks = true;
CreateBoundField("Type", "Type", false, gv);
CreateBoundField("Title", "Title", false, gv);
CreateBoundField("Date", "Date", false, gv);
CreateBoundField("ProcessTask", "ProcessTask", false, gv);
DataTable dt = new DataTable();
SPWeb web = SPContext.Current.Web;
SPListItemCollection items = web.Lists["Shared Documents"].Items;
dt.Columns.Add("Type");
dt.Columns.Add("Title");
dt.Columns.Add("Date");
dt.Columns.Add("ProcessTask");
foreach (SPListItem item in items)
{
DataRow dr = dt.NewRow();
string value = item["ProcessTask"].ToString();
value = value.Substring(value.LastIndexOf(";#") + 2);
string docicon = SPUtility.ConcatUrls("/_layouts/images",
SPUtility.MapToIcon(item.Web, SPUtility.ConcatUrls(item.Web.Url, item.Url), "", IconSize.Size16));
dr["Type"] = string.Format("<img src='{0}' />", docicon);
dr["Title"] = item.Title;
dr["Date"] = item["Created"].ToString().Split(' ')[0];
dr["ProcessTask"] = value;
dt.Rows.Add(dr);
}
gv.DataSource = dt;
gv.DataBind();
this.Controls.Add(gv);
SPListItemCollection _GridCollection = SPContext.Current.Web.Lists["Shared Documents"].Items;
DataTable _MyDatabale = _GridCollection.GetDataTable();
gvdetails.DataSource = _MyDatabale;
gvdetails.DataBind();
}
private void CreateBoundField(string sDataField, string sHeaderText, bool bReadOnly, SPGridView theGridView)
{
BoundField field = new BoundField();
field.DataField = sDataField;
field.HeaderText = sHeaderText;
field.HtmlEncode = false;
field.HeaderStyle.ForeColor = ColorTranslator.FromHtml("#808080");
field.HeaderStyle.Font.Names = new string[] { "verdana", "arial", "helvetica", "sans-serif" };
field.ItemStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
if (sHeaderText.ToLower().Equals("type"))
{
field.ItemStyle.HorizontalAlign = System.Web.UI.WebControls.HorizontalAlign.Center;
field.ItemStyle.Width = Unit.Pixel(35);
field.HeaderStyle.Width = Unit.Pixel(35);
}
field.ReadOnly = bReadOnly;
if (!bReadOnly)
field.SortExpression = sDataField;
field.Visible = true;
theGridView.Columns.Add(field);
}