我有一个电子商务网站,我已经实现了一个上传功能,用户可以上传jpeg文件,之后,他们可以立即在网格视图中看到它。这是代码:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["New"] != null)
{
if (!IsPostBack)
{
Label2.Text += Session["New"].ToString();
linkLogout.Visible = true;
//linkOrderHistory.Visible = true;
Label2.Visible = true;
linkViewProfile.Visible = true;
string[] filePaths = Directory.GetFiles(Server.MapPath("~/Uploads/"));
List<ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
files.Add(new ListItem(Path.GetFileName(filePath), filePath));
}
GridView1.DataSource = files;
GridView1.DataBind();
}
}
}
protected void UploadFile(object sender, EventArgs e)
{
string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Uploads/") + fileName);
Response.Redirect(Request.Url.AbsoluteUri);
}
protected void DownloadFile(object sender, EventArgs e)
{
string filePath = (sender as LinkButton).CommandArgument;
Response.ContentType = ContentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
Response.WriteFile(filePath);
Response.End();
}
我想要发生的是例如用户A已登录并上传文件,它仅适用于该用户。
我必须把它放在数据库上吗?任何技巧家伙?提前谢谢你。