Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.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
C# 如何从asp.net web应用程序中选择文件夹或文件?_C#_Asp.net - Fatal编程技术网

C# 如何从asp.net web应用程序中选择文件夹或文件?

C# 如何从asp.net web应用程序中选择文件夹或文件?,c#,asp.net,C#,Asp.net,我有一个ASP.NET web应用程序,需要将网页中的数据放入输出文本文件 我想让用户能够选择将保存文件的文件夹。例如,当用户单击“浏览”按钮时,应显示“选择文件夹”对话框 有可能在asp.net web应用程序中实现这样的功能吗?使用用户只能浏览其计算机上的文件。他无法查看服务器上的文件夹,除非您给他一个列表或树状视图结构,以便他可以从中进行选择。下面是构建这样一个树视图的示例。编辑: 看看你的评论,我想你的意思是推到响应流 protected void lnbDownloadFile_Cl

我有一个ASP.NET web应用程序,需要将网页中的数据放入输出文本文件

我想让用户能够选择将保存文件的文件夹。例如,当用户单击“浏览”按钮时,应显示“选择文件夹”对话框

有可能在asp.net web应用程序中实现这样的功能吗?

使用
用户只能浏览其计算机上的文件。他无法查看服务器上的文件夹,除非您给他一个列表或树状视图结构,以便他可以从中进行选择。下面是构建这样一个树视图的示例。

编辑:

看看你的评论,我想你的意思是推到响应流

 protected void lnbDownloadFile_Click(object sender, EventArgs e)
 {
  String YourFilepath;
  System.IO.FileInfo file = 
  new System.IO.FileInfo(YourFilepath); // full file path on disk
  Response.ClearContent(); // neded to clear previous (if any) written content
  Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
  Response.AddHeader("Content-Length", file.Length.ToString());
  Response.ContentType = "text/plain";
  Response.TransmitFile(file.FullName);
  Response.End();
 }
这将在浏览器中显示一个对话框,允许用户选择保存文件的位置

您想使用FileUpload控件


这种下载对话框是特定于浏览器的


请查看带有响应的通用处理程序。为此,请编写或更好地编写Http处理程序。

我不确定是否需要FileUpload控件。此控件使我能够将文件上载到服务器。我需要的是让客户端能够在其计算机上选择本地文件夹并将文件保存到此文件夹。我不需要上传文件到服务器。我需要将文件保存在本地计算机指定的文件夹中指定答案,以演示如何将文件推送到响应流。感谢您的回答!这就是我需要的。我能再问你一件事吗?是否可以在没有第一个窗口“打开或保存文件”的情况下显示“选择文件”对话框?没有问题!您在“打开/保存”方面看到的内容取决于浏览器实现,但出于安全原因,您的应用程序无法修改此对话框。回答得好!真的很有帮助!谢谢我在找这个。真的很有帮助。
protected void UploadButton_Click(object sender, EventArgs e)
  {
    // Specify the path on the server to
    // save the uploaded file to.
    String savePath = @"c:\temp\uploads\";

    // Before attempting to perform operations
    // on the file, verify that the FileUpload 
    // control contains a file.
    if (FileUpload1.HasFile)
    {
      // Get the name of the file to upload.
      String fileName = FileUpload1.FileName;

      // Append the name of the file to upload to the path.
      savePath += fileName;


      // Call the SaveAs method to save the 
      // uploaded file to the specified path.
      // This example does not perform all
      // the necessary error checking.               
      // If a file with the same name
      // already exists in the specified path,  
      // the uploaded file overwrites it.
      FileUpload1.SaveAs(savePath);

      // Notify the user of the name of the file
      // was saved under.
      UploadStatusLabel.Text = "Your file was saved as " + fileName;
    }
    else
    {      
      // Notify the user that a file was not uploaded.
      UploadStatusLabel.Text = "You did not specify a file to upload.";
    }

  }