Wednesday, August 7, 2013

How to download word/pdf/xls/ppt file in asp.net:

How to download word/pdf/xls/ppt file in asp.net:
 
public void ProcessRequest(HttpContext context)
 { 
 //context.Response.Write("Hello World"); 
 String sFileName = ""; 
 String sFullPath = String.Empty; 
 sFullPath = context.Request.QueryString["FullPath"]; 
 if (sFullPath != null && sFullPath.Length > 4) 
 { 
if (sFullPath.Contains(@"\")) 
 { 
 if (File.Exists(sFullPath)) 
 { 
 
 FileInfo _file4View = new FileInfo(sFullPath); 
 context.Response.Buffer = false; 
 context.Response.Clear(); 
 String sContentType = ""; 
 switch (Path.GetExtension(sFullPath).ToLower()) 
 { 
 case ".dwf": 
 sContentType = "Application/x-dwf"; 
 break; 
 case ".pdf": 
 sContentType = "Application/pdf"; 
 break; 
 case ".doc": 
 sContentType = "Application/vnd.ms-word"; 
 break; 
 case ".ppt": 
 case ".pps": 
 sContentType = "Application/vnd.ms-powerpoint"; 
 break; 
 case ".xls": 
 sContentType = "Application/vnd.ms-excel"; 
 break; 
 default: 
 sContentType = "Application/octet-stream"; 
 break; 
 } 
 context.Response.ContentType = sContentType;
 MemoryStream _Stream = new MemoryStream(); 
 //StreamWriter _writer = new StreamWriter(_Stream); 
 FileStream _fileStream = new FileStream(sFullPath, FileMode.Open, FileAccess.Read);
 long fileLength = _fileStream.Length; 
 Byte[] _byte = new Byte[(int)fileLength];
 _fileStream.Read(_byte, 0, (int)fileLength); 
 _fileStream.Close(); 
 context.Response.BinaryWrite(_byte); 
 } 
 } 
 } 
 } 
 

If you are searching life partner. your searching end with kpmarriage.com. now kpmarriage.com offer free matrimonial website which offer free message, free chat, free view contact information. so register here : kpmarriage.com- Free matrimonial website

0 comments:

Post a Comment