本文介绍了上传文件到asp.net中的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

if(FileUpload1.HasFile)
try
{
FileUpload1.SaveAs(C:\\\\ Users\\Vinay\\ \\ Documents \\\\\\\\\\\\\\\\\\\\\''
Label10.Text =文件名:+
FileUpload1.PostedFile.FileName +< br> +
FileUpload1.PostedFile.ContentLength +kb< br> +
内容类型:+
FileUpload1.PostedFile.ContentType;

catch(Exception ex)
{
Label10.Text =ERROR:+ ex.Message.ToString();
}
else
{
Label10.Text =您还没有指定文件。
}
// Stream obj = FileUpload1.FileContent;
// Session [file] = obj;
//Response.Redirect(\"Form3.aspx);




$ b $ p
$ b

我想要的是将上传的文件保存到文件夹命名为vini但它显示的文件,但不保存到指定的文件夹,如图所示请帮助

解决方案

首先,您需要你可以通过在字符串前加一个@,或者加双反斜杠来实现。

  FileUpload1.SaveAs(@C:\ Users \Vinay\Documents\Visual Studio 2010\WebSites\Onlinedoctorsportal\vini+ FileUpload1 。文件名); 

OR

  FileUpload1.SaveAs(C:\\ Users \\\\\\\\\\\\\\\\\\\\\\\\\\\\ FileUpload1.FileName);其次,请检查您的ASP.NET应用程序池进程正在运行的用户是否有权写入其他用户到指定的文件夹。

快速检查这是否是问题,是在您的web.config文件中模拟您的本地管理员帐户。



您可以通过配置impersonate标记来完成此操作,如下所示:

 < identity impersonate = true
userName =domain\user
password =password/>


if (FileUpload1.HasFile)
            try
            {
                FileUpload1.SaveAs("C:\\Users\\Vinay\\Documents\\Visual Studio 2010\\WebSites\\Onlinedoctorsportal\\vini" +
                     FileUpload1.FileName);
                Label10.Text = "File name: " +
                     FileUpload1.PostedFile.FileName + "<br>" +
                     FileUpload1.PostedFile.ContentLength + " kb<br>" +
                     "Content type: " +
                     FileUpload1.PostedFile.ContentType;
            }
            catch (Exception ex)
            {
                Label10.Text = "ERROR: " + ex.Message.ToString();
            }
        else
        {
            Label10.Text = "You have not specified a file.";
        }
           //Stream obj = FileUpload1.FileContent;
           //Session["file"] = obj;
           //Response.Redirect("Form3.aspx");
        }
}

what i want is to save the uploaded file to a folder named vini but it is showing the file but not saving it to the specified folder as shown please help

解决方案

Firstly you need to escape your string literal that points to the directory

You can do this by adding an @ before the string, or by putting double backslashes.

FileUpload1.SaveAs(@"C:\Users\Vinay\Documents\Visual Studio 2010\WebSites\Onlinedoctorsportal\vini" + FileUpload1.FileName);

OR

FileUpload1.SaveAs("C:\\Users\\Vinay\\Documents\\Visual Studio 2010\\WebSites\\Onlinedoctorsportal\\vini" + FileUpload1.FileName);

Secondly, check that the user that your ASP.NET application pool process is running under has permissions to write to the specified folder.

A quick check to see if this is the problem is to impersonate your local admin account in your web.config file.

You can do this by configuring the impersonate tag as follows:

<identity impersonate="true"
      userName="domain\user"
      password="password" />

这篇关于上传文件到asp.net中的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 01:27