当前位置: 首页>>代码示例>>C#>>正文


C# HttpResponse.WriteFile方法代码示例

本文整理汇总了C#中System.Web.HttpResponse.WriteFile方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse.WriteFile方法的具体用法?C# HttpResponse.WriteFile怎么用?C# HttpResponse.WriteFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.HttpResponse的用法示例。


在下文中一共展示了HttpResponse.WriteFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Real

        private void Real(HttpResponse response, HttpRequest request)
        {
            if (File.Exists(request.PhysicalPath))
            {
                FileInfo file = new System.IO.FileInfo(request.PhysicalPath);
                response.Clear();
                response.AddHeader("Content-Disposition", "filename=" + file.Name);
                response.AddHeader("Content-Length", file.Length.ToString());
                string fileExtension = file.Extension.ToLower();
                switch (fileExtension)
                {
                    case ".mp3":
                        response.ContentType = "audio/mpeg3";
                        break;
                    case ".mpeg":
                        response.ContentType = "video/mpeg";
                        break;
                    case ".jpg":
                        response.ContentType = "image/jpeg";
                        break;
                    case ".bmp":
                        response.ContentType = "image/bmp";
                        break;
                    case ".gif":
                        response.ContentType = "image/gif";
                        break;
                    case ".doc":
                        response.ContentType = "application/msword";
                        break;
                    case ".css":
                        response.ContentType = "text/css";
                        break;
                    case ".html":
                        response.ContentType = "text/html";
                        break;
                    case ".htm":
                        response.ContentType = "text/html";
                        break;
                    case ".swf":
                        response.ContentType = "application/x-shockwave-flash";
                        break;
                    case ".exe":
                        response.ContentType = "application/octet-stream";
                        break;
                    case ".inf":
                        response.ContentType = "application/x-texinfo";
                        break;
                    default:
                        response.ContentType = "application/octet-stream";
                        break;
                }

                response.WriteFile(file.FullName);
                response.End();
            }
            else
            {
                response.Write("File Not Exists");
            }
        }
开发者ID:Xiaoyuyexi,项目名称:LMS,代码行数:60,代码来源:HttpNotFound.cs

示例2: Real

        private void Real(HttpResponse response, HttpRequest request)
        {
            if (File.Exists(request.PhysicalPath))
            {
                FileInfo file = new System.IO.FileInfo(request.PhysicalPath);
                response.Clear();
                response.AddHeader("Content-Disposition", "filename=" + file.Name);
                response.AddHeader("Content-Length", file.Length.ToString());
                string fileExtension = file.Extension.ToLower();
                switch (fileExtension)
                {
                   
                    case ".jpg":
                        response.ContentType = "image/jpeg";
                        break;
                    case ".gif":
                        response.ContentType = "image/gif";
                        break;
                    case ".png":
                        response.ContentType = "image/png";
                        break;
                    default:
                        response.ContentType = "application/octet-stream";
                        break;
                }

                response.WriteFile(file.FullName);
                response.End();
            }
            else
            {
                response.Write("File Not Exists");
            }
        }
开发者ID:Xiaoyuyexi,项目名称:LMS,代码行数:34,代码来源:HttpImg.cs

示例3: WriteFile

 private static void WriteFile(HttpResponse response, HttpRequest request, string virtualPath)
 {
     var filePath = GetRealLocation(request, virtualPath);
     if (filePath != null && File.Exists(filePath))
     {
         response.ContentType = "application/javascript";
         response.WriteFile(Path.GetFileName(filePath));
     }
     else
         Return404(response);
 }
开发者ID:KyorCode,项目名称:Bootcamp2013,代码行数:11,代码来源:JavascriptHandler.cs

示例4: SendToResponse

    /// <summary>
    /// Sends the file to the response with content-length header. will check last-writetime for sending modified header
    /// </summary>
    /// <param name="Response"></param>
    /// <param name="file"></param>
    /// <param name="mimetype"></param>
    /// <remarks>Works with all types of files, not image specific</remarks>
    public void SendToResponse(HttpResponse Response, FileInfo file, string mimetype)
    {
      Response.ClearHeaders();
      setCacheHeaders(Response);   

      //Response.Cache.SetETag("\"999ed196eeb0cc1:9\"");
      Response.Cache.SetLastModified(file.LastWriteTime);
      Response.ContentType = mimetype;      
      Response.AppendHeader("Content-Length", file.Length.ToString());
      Response.WriteFile(file.FullName);
      Response.End();
    }
开发者ID:BaoToan94,项目名称:q42.wheels.gimmage,代码行数:19,代码来源:HttpImageServer.cs

示例5: WriteResponse

		/// <summary>
		/// 写入文件到http回应中
		/// </summary>
		/// <param name="response"></param>
		public void WriteResponse(HttpResponse response) {
			// 设置文件的最后修改时间
			var lastModified = File.GetLastWriteTimeUtc(FilePath).Truncate();
			response.Cache.SetLastModified(lastModified);
			// 文件没有修改时返回304
			if (IfModifiedSince != null && IfModifiedSince == lastModified) {
				response.StatusCode = 304;
				response.SuppressContent = true;
				return;
			}
			// 写入文件到http回应中
			response.ContentType = MimeMapping.GetMimeMapping(FilePath);
			response.WriteFile(FilePath);
		}
开发者ID:daywrite,项目名称:ZKWeb,代码行数:18,代码来源:FileResult.cs

示例6: Exportar

        public static void Exportar(string nombreArchivo, IList titulos, IList propiedades, IList elementos, HttpResponse response, string tituloPrincipal)
        {
            string pathArchivo = ConfigurationManager.AppSettings["PATH_TEMP"] + nombreArchivo;

            FileInfo archivo = new FileInfo(pathArchivo);
            StreamWriter handlerArchivo = archivo.CreateText();

            handlerArchivo.WriteLine(tituloPrincipal);

            // Escribir encabezado
            string linea = "";

            foreach (string titulo in titulos)
            {
                linea += "=CONCATENAR(\"\";\"" + titulo + "\";\"\")\t";
            }

            handlerArchivo.WriteLine(linea);

            // Escribir contenido
            foreach (object elemento in elementos)
            {
                linea = "";

                foreach (string propiedad in propiedades)
                {
                    linea += "=CONCATENAR(\"\";\"" + ReflectionUtils.GetProperty(elemento, propiedad) + "\";\"\")\t";
                }

                handlerArchivo.WriteLine(linea);
            }

            // Genero la salida
            handlerArchivo.Close();
            response.AppendHeader("content-disposition", "attachment; filename=" + nombreArchivo);
            response.ContentType = "application / msexcel";
            response.WriteFile(pathArchivo);
            response.End();
        }
开发者ID:Nilphy,项目名称:6671sistemasgraficos,代码行数:39,代码来源:XlsUtils.cs

示例7: WriteResponse

		/// <summary>
		/// 渡された HttpResponse にレスポンスを書き込みます。
		/// </summary>
		public override void WriteResponse(HttpResponse response){
			WriteResponseHeader(response);
			WriteAdditionalHeader(response);
			SetLastModified(response);
			response.WriteFile(FileSource.FullName);
		}
开发者ID:bakera,项目名称:Hatomaru.dll,代码行数:9,代码来源:fileresponse.cs

示例8: print_bug

		///////////////////////////////////////////////////////////////////////
		public static void print_bug (HttpResponse Response, DataRow dr, IIdentity identity, bool include_style, bool images_inline, bool history_inline, bool internal_posts)
		{

			int bugid = Convert.ToInt32(dr["id"]);
			string string_bugid = Convert.ToString(bugid);

            if (include_style) // when sending emails
            {
                Response.Write("\n<style>\n");

                // If this file exists, use it.

                string css_for_email_file = Util.GetAbsolutePath("custom\\btnet_css_for_email.css");

                try
                {
                    if (System.IO.File.Exists(css_for_email_file))
                    {
                        Response.WriteFile(css_for_email_file);
					    Response.Write("\n");
                    }
                    else
                    {
                        css_for_email_file = Util.GetAbsolutePath("btnet_base.css");
                        Response.WriteFile(css_for_email_file);
					    Response.Write("\n");
                        css_for_email_file = Util.GetAbsolutePath("custom\\btnet_custom.css");
                        if (System.IO.File.Exists(css_for_email_file))
                        {
                            Response.WriteFile(css_for_email_file);
                            Response.Write("\n");
                        }
                    }
                }
                catch (Exception e)
                {
                    btnet.Util.write_to_log("Exception trying to read css file for email \"" 
                        + css_for_email_file
                        + "\":" 
                        + e.Message);
                }

                // underline links in the emails to make them more obvious
                Response.Write("\na {text-decoration: underline; }");
                Response.Write("\na:visited {text-decoration: underline; }");
                Response.Write("\na:hover {text-decoration: underline; }");
                Response.Write("\n</style>\n");
            }

			Response.Write ("<body style='background:white'>");
			Response.Write ("<b>"
				+ btnet.Util.capitalize_first_letter(btnet.Util.get_setting("SingularBugLabel","bug"))
				+ " ID:&nbsp;<a href="
				+ btnet.Util.get_setting("AbsoluteUrlPrefix","http://127.0.0.1/")
				+ "edit_bug.aspx?id="
				+ string_bugid
				+ ">"
				+ string_bugid
				+ "</a>");

            if (btnet.Util.get_setting("EnableMobile", "0") == "1")
            {
                Response.Write(
                    "&nbsp;&nbsp;&nbsp;&nbsp;Mobile link:&nbsp;<a href="
                    + btnet.Util.get_setting("AbsoluteUrlPrefix", "http://127.0.0.1/")
                    + "mbug.aspx?id="
                    + string_bugid
                    + ">"
                    + btnet.Util.get_setting("AbsoluteUrlPrefix", "http://127.0.0.1/")
                    + "mbug.aspx?id="
                    + string_bugid
                    + "</a>");

            }

            Response.Write("<br>");

			Response.Write ("Short desc:&nbsp;<a href="
				+ btnet.Util.get_setting("AbsoluteUrlPrefix","http://127.0.0.1/")
				+ "edit_bug.aspx?id="
				+ string_bugid
				+ ">"
				+ HttpUtility.HtmlEncode((string)dr["short_desc"])
				+ "</a></b><p>");

			// start of the table with the bug fields
			Response.Write ("\n<table border=1 cellpadding=3 cellspacing=0>");
            Response.Write("\n<tr><td>Last changed by<td>"
				+ format_username((string)dr["last_updated_user"],(string)dr["last_updated_fullname"])
				+ "&nbsp;");
            Response.Write("\n<tr><td>Reported By<td>"
				+ format_username((string)dr["reporter"],(string)dr["reporter_fullname"])
				+ "&nbsp;");
            Response.Write("\n<tr><td>Reported On<td>" + btnet.Util.format_db_date_and_time(dr["reported_date"]) + "&nbsp;");

            if (identity.GetTagsFieldPermissionLevel() > 0)
	            Response.Write("\n<tr><td>Tags<td>" + dr["bg_tags"] + "&nbsp;");

            if (identity.GetProjectFieldPermissionLevel() > 0)
//.........这里部分代码省略.........
开发者ID:jhadwen,项目名称:BugTracker.NET,代码行数:101,代码来源:print_bug.cs

示例9: DownloadFile

        /// <summary>
        /// Writes file to response.
        /// </summary>
        public void DownloadFile(String path, String localFileName, String originalFileName,
            String contentType, HttpResponse response)
        {
            if (!System.IO.File.Exists(path + localFileName))
            {
                return;
            }
            response.ClearContent();
            response.ClearHeaders();
            response.ContentType = contentType;
            response.AddHeader("content-disposition",
                               "attachment; filename=" + originalFileName);

            response.WriteFile(path + localFileName);
            response.End();
        }
开发者ID:ala--rs88,项目名称:DNN-DocumentsExchangeModule,代码行数:19,代码来源:DocumentsExchangeModuleController.cs

示例10: SendResponse


//.........这里部分代码省略.........
            {
                response.AddHeader("X-CKFinder-Error", Errors.ThumbnailsDisabled.ToString());
                response.StatusCode = 403;
                response.End();
                return;
            }

            if (!CurrentFolder.CheckAcl(AccessControlRules.FileView))
            {
                response.AddHeader("X-CKFinder-Error", Errors.Unauthorized.ToString());
                response.StatusCode = 403;
                response.End();
                return;
            }

            bool is304 = false;

            string fileName = HttpContext.Current.Request["FileName"];

            string thumbFilePath = Path.Combine(CurrentFolder.ThumbsServerPath, fileName.Replace("/", "\\"));

            if (!Connector.CheckFileName(fileName))
            {
                response.AddHeader("X-CKFinder-Error", Errors.InvalidRequest.ToString());
                response.StatusCode = 403;
                response.End();
                return;
            }

            if (Config.Current.CheckIsHiddenFile(fileName))
            {
                response.AddHeader("X-CKFinder-Error", string.Format("{0} - Hidden folder", Errors.FileNotFound));
                response.StatusCode = 404;
                response.End();
                return;
            }

            // If the thumbnail file doesn't exists, create it now.
            if (!File.Exists(thumbFilePath))
            {
                string sourceFilePath = Path.Combine(CurrentFolder.ServerPath, fileName);

                if (!File.Exists(sourceFilePath))
                {
                    response.AddHeader("X-CKFinder-Error", Errors.FileNotFound.ToString());
                    response.StatusCode = 404;
                    response.End();
                    return;
                }

                ImageTools.ResizeImage(sourceFilePath, thumbFilePath, Config.Current.Thumbnails.MaxWidth, Config.Current.Thumbnails.MaxHeight, true, Config.Current.Thumbnails.Quality);
            }

            var thumbfile = new FileInfo(thumbFilePath);

            string eTag = thumbfile.LastWriteTime.Ticks.ToString("X") + "-" + thumbfile.Length.ToString("X");

            string chachedETag = Request.ServerVariables["HTTP_IF_NONE_MATCH"];
            if (!string.IsNullOrEmpty(chachedETag) && eTag == chachedETag)
                is304 = true;

            if (!is304)
            {
                string cachedTimeStr = Request.ServerVariables["HTTP_IF_MODIFIED_SINCE"];
                if (!string.IsNullOrEmpty(cachedTimeStr))
                {
                    try
                    {
                        DateTime cachedTime = DateTime.Parse(cachedTimeStr);

                        if (cachedTime >= thumbfile.LastWriteTime)
                            is304 = true;
                    }
                    catch
                    {
                        is304 = false;
                    }
                }
            }

            if (is304)
            {
                response.StatusCode = 304;
                response.End();
                return;
            }

            string thumbFileExt = Path.GetExtension(thumbFilePath).TrimStart('.').ToLower();

            if (thumbFilePath == ".jpg")
                response.ContentType = "image/jpeg";
            else
                response.ContentType = "image/" + thumbFileExt;

            response.Cache.SetETag(eTag);
            response.Cache.SetLastModified(thumbfile.LastWriteTime);
            response.Cache.SetCacheability(HttpCacheability.Private);

            response.WriteFile(thumbFilePath);
        }
开发者ID:sidneylimafilho,项目名称:InfoControl,代码行数:101,代码来源:ThumbnailCommandHandler.cs

示例11: WriteFile_PermitOnly_UnmanagedCode

		public void WriteFile_PermitOnly_UnmanagedCode ()
		{
			HttpResponse response = new HttpResponse (writer);
			response.WriteFile (handle, 0, 1);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:5,代码来源:HttpResponseCas.cs

示例12: WriteResponse

 public override void WriteResponse(HttpResponse response)
 {
     response.ContentType = this.ContentType;
     if(myFile.Exists) response.WriteFile(myFile.FullName);
 }
开发者ID:bakera,项目名称:ECCM,代码行数:5,代码来源:imageresponse.cs

示例13: transmitify

 void transmitify(HttpResponse response, FileInfo fi)
 {
     response.StatusCode = 200;
     response.AddHeader("ETag", fi.LastWriteTimeUtc.Ticks.ToString("x"));
     response.AddHeader("Content-Type", _compiler.OutputMimeType);
     response.AddHeader("Content-Disposition", "inline");
     response.AddHeader("Last-Modified", fi.LastWriteTimeUtc.ToString("R"));
     response.WriteFile(fi.FullName);
 }
开发者ID:arielbh,项目名称:SassAndCoffee,代码行数:9,代码来源:CompilableFileHandler.cs

示例14: HandleTransactionRequest

        /// <summary>
        /// Returns the XML for the requested transaction and removes any state files associated with it.
        /// </summary>
        /// <param name="response"><see cref="T:System.Web.HttpResponse"/></param>
        /// <param name="transaction">Transaction TcmUri</param>
        private void HandleTransactionRequest(HttpResponse response, String transaction)
        {
            Logger.Info("FileTransaction - Requested '{0}'.", transaction);

            if (TcmUri.IsValid(transaction))
            {
                String mappedFile = Path.Combine(mIncomingFolder, transaction + ".xml");

                if (File.Exists(mappedFile))
                {
                    response.ContentType = "text/xml";
                    response.WriteFile(mappedFile);

                    try
                    {
                        String stateFile = Path.Combine(mIncomingFolder, transaction + ".state.xml");
                        Logger.Debug("Removing transaction state xml '{0}'.", stateFile);

                        if (File.Exists(stateFile))
                            File.Delete(stateFile);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("FileTransaction - Removing '{0}'.", ex, ex.Message);
                    }

                    return;
                }

                Logger.Warning("FileTransaction - Not found transaction file '{0}'.", mappedFile);
            }

            Logger.Warning("FileTransaction - Invalid transaction '{0}'.", transaction);

            response.StatusCode = (int)HttpStatusCode.NoContent;
            response.Write("No Content");
        }
开发者ID:TcmExtensions,项目名称:TcmHttpUpload,代码行数:42,代码来源:HttpUpload.cs

示例15: HandleFileRequest

        /// <summary>
        /// Handles "fileName=" requests from the cd_transport service
        /// </summary>
        /// <param name="response"><see cref="T:System.Web.HttpResponse"/></param>
        /// <param name="fileName">fileName</param>
        /// <param name="action">action to take, either empty or "remove"</param>
        private void HandleFileRequest(HttpResponse response, String fileName, String action)
        {
            String mappedFile = TcmUri.IsValid(fileName) ? Path.Combine(mIncomingFolder, fileName + ".state.xml") : Path.Combine(mIncomingFolder, fileName);

            Logger.Info("FileRequest - fileName '{0}', action '{1}'.", fileName, action);

            if (File.Exists(mappedFile))
            {
                if (String.Equals(action, "remove", StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        Logger.Info("FileRequest - removing file '{0}'.", fileName);
                        File.Delete(mappedFile);
                    }
                    catch (Exception ex)
                    {
                        Logger.Error("FileRequest - removing file", ex, ex.Message);
                    }

                    response.Write("File removed");

                    return;
                }
                else
                {
                    if (String.Equals(Path.GetExtension(mappedFile), ".xml", StringComparison.OrdinalIgnoreCase))
                    {
                        response.ContentType = "text/xml";

                        if (String.Equals(fileName, META_XML, StringComparison.OrdinalIgnoreCase))
                        {
                            CleanTransactions.Execute();

                            Logger.Debug("FileRequest - meta.xml requested");

                            String metaXml = HttpContext.Current.Cache[META_XML] as String;

                            if (String.IsNullOrEmpty(metaXml))
                            {
                                metaXml = File.ReadAllText(mappedFile, Encoding.UTF8);
                                HttpContext.Current.Cache.Insert(META_XML, metaXml, new CacheDependency(mappedFile));
                            }
                            else
                            {
                                Logger.Info("FileRequest - Sending cached meta.xml");
                            }

                            response.Write(metaXml);
                            return;
                        }
                    }

                    Logger.Info("FileRequest - sending file {0}", fileName);

                    response.WriteFile(mappedFile);
                    return;
                }
            }

            Logger.Warning("FileRequest - Not found or invalid '{0}'.", mappedFile);

            response.StatusCode = (int)HttpStatusCode.NoContent;
            response.Write("No Content");
        }
开发者ID:TcmExtensions,项目名称:TcmHttpUpload,代码行数:71,代码来源:HttpUpload.cs


注:本文中的System.Web.HttpResponse.WriteFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。