ผมเขียนasp.net ให้สามารถupload ไฟล์ได้ ตอนทำที่โปรแกรม microsoft visual studio 2015 ทดลองใช้ก็สามารถใช้ได้ พอนำมาลงใน IIS 8 สามารถเปิดได้ปกติแต่พอใส่ไฟล์และกดอัพโหลด มันขึ้น 404 Not Found ผมแก้จนไม่รู้จะแก้ยังไงแล้วครับ ขอบคุณครับ
WebUpload.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebUpload.aspx.cs" Inherits="WebUpload.WebUpload" %>
<!DOCTYPE html>
<html xmlns="
http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Web Upload</title>
</head>
<body>
<h3>Upload Files</h3>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Upload" />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
: Size<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
: File Extension<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Download" />
</div>
</form>
</body>
</html>
WebUpload.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebUpload
{
public partial class WebUpload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string ext = System.IO.Path.GetExtension(FileUpload1.FileName);
string path = Server.MapPath("documents");
FileUpload1.SaveAs(path + FileUpload1.FileName);
Label1.Text = FileUpload1.PostedFile.ContentLength.ToString();
Label2.Text = FileUpload1.PostedFile.ContentType;
}
else
{
Response.Write("No file");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("
http://retina.no-ip.org/download");
}
}
}
asp.net upload ไฟล์ไม่ได้
WebUpload.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebUpload.aspx.cs" Inherits="WebUpload.WebUpload" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Web Upload</title>
</head>
<body>
<h3>Upload Files</h3>
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Upload" />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
: Size<br />
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
: File Extension<br />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Download" />
</div>
</form>
</body>
</html>
WebUpload.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebUpload
{
public partial class WebUpload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string ext = System.IO.Path.GetExtension(FileUpload1.FileName);
string path = Server.MapPath("documents");
FileUpload1.SaveAs(path + FileUpload1.FileName);
Label1.Text = FileUpload1.PostedFile.ContentLength.ToString();
Label2.Text = FileUpload1.PostedFile.ContentType;
}
else
{
Response.Write("No file");
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("http://retina.no-ip.org/download");
}
}
}