本文整理汇总了C#中System.Web.HttpResponse.TransmitFile方法的典型用法代码示例。如果您正苦于以下问题:C# HttpResponse.TransmitFile方法的具体用法?C# HttpResponse.TransmitFile怎么用?C# HttpResponse.TransmitFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.TransmitFile方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TransmitFile
/// <summary>
/// Writes the requested file from the package directly to the response.
/// This method clears the response before sending the file and provides an option to skip
/// package validation.
/// </summary>
/// <param name="filePath"></param>
/// <param name="response"></param>
/// <param name="skipValidation"></param>
internal void TransmitFile(string filePath, HttpResponse response, bool skipValidation)
{
Utilities.ValidateParameterNonNull("filePath", filePath);
Utilities.ValidateParameterNotEmpty("filePath", filePath);
Utilities.ValidateParameterNonNull("response", response);
if (!skipValidation)
{
using (ImpersonateIdentity id = new ImpersonateIdentity(m_impersonationBehavior))
{
// If user does not have access, a UnauthorizedAccess Exception is thrown
Directory.GetFiles(m_packageBasePath);
// Check if package has valid e-learning content
if (!ManifestExists())
throw new InvalidPackageException(Resources.ImsManifestXmlMissing);
}
}
string absoluteFilePath = SafePathCombine(m_packageBasePath, filePath);
response.Clear();
response.Buffer = false;
response.BufferOutput = false;
using (ImpersonateIdentity id = new ImpersonateIdentity(m_impersonationBehavior))
{
response.TransmitFile(absoluteFilePath);
}
}
示例2: TransmitFile_PermitOnly_FileIOPermission
public void TransmitFile_PermitOnly_FileIOPermission ()
{
HttpResponse response = new HttpResponse (writer);
response.TransmitFile (fname);
}
示例3: ProcessDownload
//.........这里部分代码省略.........
// sending header for multipart request
if (bMultipart)
{
// if this is a multipart response, we must add
// certain headers before streaming the content:
// The multipart boundary
objResponse.Output.WriteLine("--" + MULTIPART_BOUNDARY);
// The mime type of this part of the content
objResponse.Output.WriteLine(HTTP_HEADER_CONTENT_TYPE + ": " + _responseData.ContentType);
// The actual range
// // DataLength = Total size
objResponse.Output.WriteLine(HTTP_HEADER_CONTENT_RANGE + ": bytes " +
alRequestedRangesBegin[iLoop].ToString() + "-" +
alRequestedRangesEnd[iLoop].ToString() + "/" +
_responseData.DataLength.ToString());
// Indicating the end of the intermediate headers
objResponse.Output.WriteLine();
}
// flush the data
// Declare variables
int readed = -1;
#if dotNET20sp1
if (_responseData.IsDataFile)
{
// send file content directly
objResponse.TransmitFile(_responseData.FileName);
}
else
#endif
// Get the response stream for reading
// Read the stream and write it into memory
while ((int)(readed = objStream.Read(bBuffer, 0, bBuffer.Length)) > 0)
{
if (objResponse.IsClientConnected)
{
// write to response
objResponse.OutputStream.Write(bBuffer, 0, readed);
// send response
objResponse.Flush();
}
else
{
bDownloadBroken = true;
break;
}
}
// In Multipart responses, mark the end of the part
if (bMultipart)
objResponse.Output.WriteLine();
// No need to proceed to the next part if the
// client was disconnected
if (bDownloadBroken)
{
//break;
}
示例4: WriteNewImage
/// <summary>
/// Writes an image to the response.
/// </summary>
/// <param name="path">The path of the file.</param>
/// <param name="response">The HttpResponse to write to.</param>
static void WriteNewImage(string path, HttpResponse response)
{
response.ContentType = "image/jpeg";
response.TransmitFile(path);
}
示例5: TrySendResponseOrStartResponseCapture
public bool TrySendResponseOrStartResponseCapture(HttpResponse response)
{
byte[] responseData = null;
string responseFile = null;
// loop while trying to either send or capture the response
// (the loop is needed for cases when another thread does the capture)
for (; ; )
{
lock (this)
{
// attempt to find the cached response on disk (only once)
if (!_triedToLoadCachedResponse)
{
LookForCachedResponseOnDisk();
_triedToLoadCachedResponse = true;
}
if (_cachedResponseLoaded && ValidateLoadedCachedResponse())
{
// serve the cached response if validated
if (_serveFromMemory)
{
responseData = _cachedResponseBytes;
}
else
{
responseFile = _dataFilename;
}
// send the response outside of the lock
break;
}
// couldn't send the response - try to capture it under lock
// (don't attempt to capture the same response from 2 threads at the same time)
if (_capturingResponse == null)
{
// generate new file name
string filename = string.Format("{0}_{1:x8}{2}",
_filenamePrefix, Guid.NewGuid().ToString().GetHashCode(), TempFileExt);
_capturingFilter = new ResponseFilter(response.Filter, filename);
response.Filter = _capturingFilter;
// move the event - non-signaled state
_capturingEvent.Reset();
// remember the response
_capturingResponse = response;
// started capturing - return from this method
break;
}
}
// capturing started from another thread - wait until done and continue (outside of the lock)
_capturingEvent.WaitOne();
}
// send the cached response if available (outside of the lock)
if (responseData != null)
{
response.OutputStream.Write(responseData, 0, responseData.Length);
return true;
}
else if (responseFile != null)
{
try
{
response.TransmitFile(responseFile);
}
catch
{
// if there is a problem sending data file, invalidate the cached response
InvalidateCachedResponse();
throw;
}
return true;
}
else
{
return false;
}
}
示例6: TransmitFileUsingHttpResponse
private void TransmitFileUsingHttpResponse(HttpRequest request, HttpResponse response,
string physicalFilePath, ResponseCompressionType compressionType, FileInfo file)
{
if (file.Exists)
{
// We don't cache/compress such file types. Must be some binary file that's better
// to let IIS handle
this.ProduceResponseHeader(response, Convert.ToInt32(file.Length), compressionType,
physicalFilePath, file.LastWriteTimeUtc);
response.TransmitFile(physicalFilePath);
Debug.WriteLine("TransmitFile: " + request.FilePath);
}
else
{
throw new HttpException((int)HttpStatusCode.NotFound, request.FilePath + " Not Found");
}
}
示例7: CreateSendFileFunc
private static Func<string, long, long?, CancellationToken, Task> CreateSendFileFunc(HttpResponse response)
{
return (path, offset, byteCount, cancel) =>
{
var length = byteCount.HasValue ? byteCount.Value : -1;
response.TransmitFile(path, offset, length);
return TaskHelper.Completed();
};
}
示例8: DownloadFile
public static bool DownloadFile(HttpResponse Response, HttpRequest Request, string filePath, string outputFileName, bool responseEnd,bool clearCache)
{
try
{
Response.ClearContent();
string fileExtension = Path.GetExtension(outputFileName).ToLower();
switch (fileExtension)
{
case ".gif":
Response.ContentType = "image/gif";
break;
case ".swf":
case ".flv":
Response.ContentType = "application/x-shockwave-flash";
break;
case ".rmvb":
case ".rm":
Response.ContentType = "audio/x-pn-realaudio";
break;
case ".mp3":
case ".mpeg":
case ".mpg":
Response.ContentType = "audio/mpeg";
break;
case ".wav":
Response.ContentType = "audio/x-wav";
break;
case ".ra":
Response.ContentType = "audio/x-realaudio";
break;
case ".avi":
Response.ContentType = "video/x-msvideo";
break;
case ".mov":
Response.ContentType = "video/quicktime";
break;
default:
Response.ContentType = "application/octet-stream";
break;
}
// �ļ���
//
if (!string.IsNullOrEmpty(outputFileName))
{
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(Encoding.GetEncoding(65001).GetBytes(outputFileName)));
}
Response.TransmitFile(filePath);
if (clearCache)
{
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.Cache.SetNoStore();
}
if (responseEnd)
Response.End();
}
catch
{
return false;
}
return true;
}
示例9: DownLoadFileByByteEX
public static void DownLoadFileByByteEX(byte[] buffers, HttpResponse response, string fileName, string filePath)
{
response.Clear();
response.ClearContent();
response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, Encoding.UTF8));
response.AppendHeader("Content-Length ", buffers.Length.ToString());
response.ContentType = "application/pdf";
response.TransmitFile(filePath);
//response.Flush();
//response.End();
}
示例10: DownloadFile
/// <summary>
/// Bietet die geforderte Datei zum Download an.
/// </summary>
/// <param name="file"></param>
private void DownloadFile(HttpRequest request, HttpResponse response, ModuleConfig cfg, string file, bool asAttachment)
{
// Ermitteln des Filewappers der entsprechenden Datei.
ConfigAgent cfgAgent = new ConfigAgent(cfg);
FileWrapper dwnFile = cfgAgent.RootDirectory.GetFile(file);
if (dwnFile != null)
{
response.CacheControl = "public";
response.Cache.SetCacheability(HttpCacheability.Private);
if (asAttachment)
response.AddHeader("Content-Disposition", "attachment; filename=" + dwnFile.FileName);
response.AddHeader("Content-Length", dwnFile.FileSize.ToString());
String mimeType = dwnFile.MimeType;
if (mimeType != null)
response.ContentType = mimeType;
response.TransmitFile(dwnFile.PhysicalPath);
if(!Portal.API.Statistics.StatisticHelper.IsBot(request))
{
// In der Statistik zwischenspeichern.
Statistic FbStatistic = new Statistic(cfgAgent.PhysicalRoot);
FbStatistic.DownloadFile(file);
}
}
else
throw new FileNotFoundException();
}
示例11: Transmit
public bool Transmit(HttpResponse response, string sprocketPath)
{
CacheItemInfo info = null;
bool memCached;
lock (sprocketPathMemoryCache)
memCached = sprocketPathMemoryCache.TryGetValue(sprocketPath, out info);
if (info != null)
info = ValidateCacheItem(info);
if (info == null)
{
info = CheckDBForSprocketPath(sprocketPath);
if (info == null)
return false;
lock (sprocketPathMemoryCache)
sprocketPathMemoryCache[sprocketPath] = info;
}
if (!File.Exists(info.PhysicalPath))
{
if (memCached)
lock (sprocketPathMemoryCache)
sprocketPathMemoryCache.Remove(sprocketPath);
return false;
}
response.ContentType = info.ContentType;
response.TransmitFile(info.PhysicalPath);
return true;
}
示例12: ForceDownload
public static void ForceDownload(string FilePath, HttpResponse objResponse)
{
string strType = null;
string strName = Path.GetFileName(FilePath);
string strExt = Path.GetExtension(FilePath).ToLower();
//Set Content Type for Response
switch (strExt)
{
case ".htm":
case ".html":
strType = "text/HTML";
break;
case ".txt":
strType = "text/plain";
break;
case ".rtf":
strType = "application/rtf";
break;
case ".csv":
strType = "Application/x-msexcel";
break;
case ".pdf":
strType = "application/pdf";
break;
case ".asf":
strType = "video/x-ms-asf";
break;
case ".avi":
strType = "video/avi";
break;
case ".doc":
strType = "application/msword";
break;
case ".zip":
strType = "application/zip";
break;
case ".xls":
strType = "application/vnd.ms-excel";
break;
case ".gif":
strType = "image/gif";
break;
case ".jpg":
case "jpeg":
strType = "image/jpeg";
break;
case ".wav":
strType = "audio/wav";
break;
case ".mp3":
strType = "audio/mpeg3";
break;
case ".mpg":
case "mpeg":
strType = "video/mpeg";
break;
case ".asp":
strType = "text/asp";
break;
default:
//Handle All Other Files
strType = "application/octet-stream";
break;
}
objResponse.ContentType = strType;
objResponse.AppendHeader("content-disposition", "attachment; filename=" + strName);
objResponse.TransmitFile(FilePath);
objResponse.End();
}
示例13: WriteFile
protected override void WriteFile(HttpResponse response)
{
response.AddHeader("Content-Length", new FileInfo(FileName).Length.ToString());
response.TransmitFile(FileName);
}