Open file from browser

Response.ContentType = “application/pdf”;

Response.AddHeader(“content-disposition”, “attachment; filename=” + path);




Note. Comment second line to hide download file dialog OR change with this line

Response.AddHeader(“content-disposition”, “inline; filename=” + directory + pathFile);

Get location outside of website folder

webRootPath = Server.MapPath(“~”);

docPath = Path.GetFullPath(Path.Combine(webRootPath, “..\Documents\MyDocument.xml”));

Get hidden column value in Gridview

CSS: .hideGridColumn {display: none;}

ASP.NET: <asp:BoundField DataField = “AddressID” HeaderText = “AddressID” HeaderStyle-CssClass = “hideGridColumn” ItemStyle-CssClass = “hideGridColumn” />

C#: //Create a list of integer to store selected AddressId

List<int> lstAddressId = new List<int>();

Control chkSelect = null;

for(int iRow = 0; iRow < gvAddress.Rows.Count; iRow++){

//Find checkBox control in GridView

chkSelect = gvAddress.Rows[iRow].Cells[0].FindControl(“chkSelect”);

if(chkSelect != null){

//If CheckBox is checked then add AddressId of selected row in List by using gvAddress.Rows[iRow].Cells[1].Text property


int iAddressId = (int)gvAddress.Rows[iRow].Cells[1].Text;





Convert Base64 String to Image

//Convert Base64 String to byte[]

byte[] imageBytes = Convert.FromBase64String(stringHere);

MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);

//Convert byte[] to Image

ms.Write(imageBytes, 0 , imageBytes.Length);

System.Drawing.Image img = System.Drawing.Image.FromStream(ms, true);

img.Save(HttpRuntime.AppDomainAppPath + @”\test.png”);

Image1.Image = @”\test.png”;

Avoid getting NULL value


//code here