最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

asp.net 文件下載功能函數(shù)代碼整理

 更新時(shí)間:2010年04月03日 16:54:35   作者:  
asp.net下文件下載功能代碼,fullFilename 要下載的文件的路徑+文件名,需要的朋友可以參考下。
復(fù)制代碼 代碼如下:

public void FileDownLoadDel(string fullFilename)
{
System.IO.Stream iStream = null;
// Buffer to read 10K bytes in chunk:
byte[] buffer = new Byte[10000];
// Length of the file:
int length;
// Total bytes to read:
long dataToRead;
// Identify the file to download including its path.
string filepath = fullFilename;
filepath = Server.MapPath(filepath);
// Identify the file name.
string filename = System.IO.Path.GetFileName(filepath);

try
{
// Open the file.
iStream = new System.IO.FileStream(filepath, System.IO.FileMode.Open,
System.IO.FileAccess.Read, System.IO.FileShare.Read);

// Total bytes to read:
dataToRead = iStream.Length;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
// Read the bytes.
while (dataToRead > 0)
{
// Verify that the client is connected.
if (Response.IsClientConnected)
{
// Read the data in buffer.
length = iStream.Read(buffer, 0, 10000);
// Write the data to the current output stream.
Response.OutputStream.Write(buffer, 0, length);
// Flush the data to the HTML output.
Response.Flush();
buffer = new Byte[10000];
dataToRead = dataToRead - length;
}
else
{
//prevent infinite loop if user disconnects
dataToRead = -1;
Response.Clear();
}
}
Response.End(); //沒(méi)有這句會(huì)將該頁(yè)面刷新后的內(nèi)容追加寫(xiě)入文件中。
}
catch (Exception ex)
{
// Trap the error, if any.
//Response.Write("Error : " + ex.Message);
//base.WriteLog("資料", "下載資料:" + ex.Message + "!", LogType.Error, this.GetType().ToString());
}
finally
{
if (iStream != null)
{
//Close the file.
iStream.Close();
}
File.Delete(fullFilename);
}
}

相關(guān)文章

最新評(píng)論

白河县| 武鸣县| 南陵县| 明溪县| 西乡县| 石楼县| 老河口市| 府谷县| 塔城市| 观塘区| 齐齐哈尔市| 朝阳区| 甘南县| 花垣县| 尤溪县| 屏南县| 长岛县| 缙云县| 呼伦贝尔市| 汶上县| 乌拉特后旗| 尤溪县| 板桥市| 黔西| 潞西市| 康定县| 黔西县| 道孚县| 安达市| 神木县| 长兴县| 林周县| 哈尔滨市| 温州市| 巢湖市| 游戏| 合山市| 通州区| 赣州市| 深泽县| 咸宁市|