Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用asp.net将我的文件上载到文件夹_Asp.net - Fatal编程技术网

使用asp.net将我的文件上载到文件夹

使用asp.net将我的文件上载到文件夹,asp.net,Asp.net,我想把我的文件上传到像 FileUpload1.SaveAs(Server.MapPath("~/admin_file/") + FileUpload1.FileName); 这里是我的文件夹名admin\u文件 protected void BindGrid() { string[] filePaths = Directory.GetFiles(Server.MapPath("~/admin_file/")); List<ListItem> files = new

我想把我的文件上传到像

FileUpload1.SaveAs(Server.MapPath("~/admin_file/") + FileUpload1.FileName);
这里是我的文件夹名admin\u文件

protected void BindGrid() {
    string[] filePaths = Directory.GetFiles(Server.MapPath("~/admin_file/"));
    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 btnUpload_Click(object sender, EventArgs e)
{
    if (FileUpload1.HasFile)
    {
        FileUpload1.SaveAs(Server.MapPath("~/admin_file/") + FileUpload1.FileName);
        BindGrid();
    }
    else
    {
        //Response.Write("Please select file to upload");
        string message = "alert('Please select file to upload!')";
        ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", message, true);
    }

}
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();
}
protected void DeleteFile(object sender, EventArgs e)
{
    string filePath = (sender as LinkButton).CommandArgument;
    File.Delete(filePath);
    string message = "alert('Deleted Successfully!')";
    ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", message, true);
    BindGrid();
}
受保护的void BindGrid(){
string[]filepath=Directory.GetFiles(Server.MapPath(“~/admin\u file/”);
列表文件=新列表();
foreach(文件路径中的字符串文件路径)
{
添加(新列表项(Path.GetFileName(filePath),filePath));
}
GridView1.DataSource=文件;
GridView1.DataBind();
}
受保护的void btnUpload\u单击(对象发送方,事件参数e)
{
if(FileUpload1.HasFile)
{
FileUpload1.SaveAs(Server.MapPath(“~/admin\u file/”)+FileUpload1.FileName);
BindGrid();
}
其他的
{
//响应。写入(“请选择要上载的文件”);
string message=“警报('请选择要上载的文件!')”;
ScriptManager.RegisterClientScriptBlock((发送方作为控件),this.GetType(),“警报”,消息,true);
}
}
受保护的void下载文件(对象发送方,事件参数e)
{
字符串filePath=(发送方为LinkButton).CommandArgument;
Response.ContentType=ContentType;
AppendHeader(“内容处置”、“附件;文件名=“+Path.GetFileName(filePath));
Response.WriteFile(文件路径);
Response.End();
}
受保护的void DeleteFile(对象发送方,事件参数e)
{
字符串filePath=(发送方为LinkButton).CommandArgument;
File.Delete(文件路径);
string message=“警报('Deleted Successfully!”)”;
ScriptManager.RegisterClientScriptBlock((发送方作为控件),this.GetType(),“警报”,消息,true);
BindGrid();
}
该程序在本地系统中成功执行。当我将此程序发布到GODADDY时,不支持任何人告诉我如何给出此路径

否则发送邮件pramadivi@gmail.com

阅读此故障诊断与排除,并根据其进行操作

在连接文件夹+文件名时,最好使用Path.Combine

FileUpload1.SaveAs(System.IO.Path.Combine(pathToFolder, fileName));

您遇到了什么错误?听起来像是Godaddy的目录权限问题。查看这篇文章,了解如何更改管理员文件目录上的隐私设置的详细信息。。。