System.Web.HttpResponse.WriteFile C# (CSharp) Method

WriteFile() public method

public WriteFile ( string filename, bool readIntoMemory ) : void
filename string
readIntoMemory bool
return void
		public void WriteFile (string filename, bool readIntoMemory)
		{
			if (filename == null)
				throw new ArgumentNullException ("filename");

			string fn = GetNormalizedFileName (filename);
			if (readIntoMemory){
				using (FileStream fs = File.OpenRead (fn))
					WriteFile (fs, 0, fs.Length);
			} else {
				FileInfo fi = new FileInfo (fn);
				output_stream.WriteFile (fn, 0, fi.Length);
			}
			if (buffer)
				return;

			output_stream.ApplyFilter (false);
			Flush ();
		}

Same methods

HttpResponse::WriteFile ( FileStream fs, long offset, long size ) : void
HttpResponse::WriteFile ( IntPtr fileHandle, long offset, long size ) : void
HttpResponse::WriteFile ( string filename ) : void
HttpResponse::WriteFile ( string filename, long offset, long size ) : void

Usage Example

Example #1
0
        public bool ReturnXls(System.Web.HttpResponse resp, string fileName)
        {
            System.IO.FileInfo f = new System.IO.FileInfo(fileName);
            resp.ClearHeaders();
            resp.ClearContent();

            DialogUtils.SetCookieResponse(resp);

            resp.HeaderEncoding = System.Text.Encoding.Default;
            resp.AddHeader("Content-Disposition", "attachment; filename=" + f.Name);
            resp.AddHeader("Content-Length", f.Length.ToString());
            resp.ContentType = "application/octet-stream";
            resp.Cache.SetCacheability(HttpCacheability.NoCache);

            /*
             * resp.BufferOutput = false;
             * resp.WriteFile(f.FullName);
             * resp.Flush();
             * resp.End();
             */

            resp.BufferOutput = true;
            resp.WriteFile(f.FullName);
            //resp.End();
            return(true);
        }
All Usage Examples Of System.Web.HttpResponse::WriteFile