using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace GodaddyImages
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string[] filePaths = Directory.GetFiles(Server.MapPath("~\\Images\\"));
List<ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
string fileName = Path.GetFileName(filePath);
files.Add(new ListItem(fileName, "~\\Images\\" + fileName));
}
GridView1.DataSource = files;
GridView1.DataBind();
}
}
protected void Upload(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath("~\\Images\\") + fileName);
Response.Redirect(Request.Url.AbsoluteUri);
}
}
}
}
任何人都可以告诉我如何将图像从asp.net上传到godaddy服务器。 我可以将图像上传到本地文件夹,但发现很难上传到godaddy服务器
答案 0 :(得分:0)
通常在本地系统中,您将具有写入文件的权限(在本例中为图像)。但是,当您出于安全目的使用服务器(或共享主机)时,它们将为您提供对您部署的文件夹的只读访问权限。但是,如果您是托管该域的管理员,那么您可以继续更改它的权限。从asp.net上传所需的代码如下:
fileUpload.SaveAs(Server.MapPath("~/Images/") + fileUpload.FileName);
但是,仍然需要对该特定文件夹具有适当的写入权限。
希望,这有帮助。