-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShowFile.aspx.cs
70 lines (67 loc) · 2.35 KB
/
ShowFile.aspx.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
public partial class Download : System.Web.UI.Page
{
string sdkRoot = "C:\\Inetpub\\wwwroot\\sdk\\";
protected void Page_Load(object sender, EventArgs e)
{
string fileName = this.Request.QueryString["file"];
if (fileName != null)
{
FileInfo file = new FileInfo(fileName);
if (file.Exists)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "filename=" + file.Name);
Response.AddHeader("Content-Length", file.Length.ToString());
switch (file.Extension.ToLower())
{
case ".map":
Response.ContentType = "text/plain";
break;
case ".xml":
Response.ContentType = "text/plain";
break;
case ".js":
Response.ContentType = "text/plain";
break;
case ".txt":
Response.ContentType = "text/plain";
break;
case ".html":
Response.ContentType = "text/html";
break;
case ".png":
Response.ContentType = "image/png";
break;
case ".gif":
Response.ContentType = "image/gif";
break;
case ".jpeg":
Response.ContentType = "image/jpeg";
break;
default:
Response.ContentType = "application/octet-stream";
break;
}
if (Response.ContentType.StartsWith("image") && file.Length == 0)
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.End();
}
else
{
Response.Write("This file does not exist.");
}
}
else
{
Response.Write("Please provide a file to show.");
}
}
}