String ext = String.Empty; if (strFile.IndexOf(".") > 0) ext = (strFile.Split('.'))[1]; if (ext.ToLower() == "txt") Response.ContentType = "text/html"; if (ext.ToLower() == "xls") Response.ContentType = "xls/html"; if (ext.ToLower() == "pdf") Response.ContentType = "application/pdf"; ////combine the path and file name if (File.Exists(strFile))//open the file and process it { FileStream sourceFile = new FileStream(strFile, FileMode.Open, FileAccess.Read); long FileSize; FileSize = sourceFile.Length; Response.AddHeader("Content-Length", FileSize.ToString()); //* byte[] getContent = new byte[(int)FileSize]; sourceFile.Read(getContent, 0, (int)FileSize); sourceFile.Close(); Response.BinaryWrite(getContent); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)