1

Web ページを作成し、その中に「BrowseButton」という名前の参照ボタンと「BrowseTextBox」という名前のテキスト ボックスを作成しました。

バックエンド コードは次のとおりです。

protected void BrowseButtonClick(object sender, EventArgs e)

        {
            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.ShowDialog();
            BrowseTextBox.Text = openFileDialog1.FileName;
        }

しかし、私は取得してThreadStateExceptionいて、それを処理する方法がわかりません....

4

2 に答える 2

0

FolderBrowserDialogポップアップが表示される唯一の方法はServer-Side、プログラムが入力を永遠に待つことになるため、これは機能しません。

ニーズにより適したこのWeb コントロールを使用する必要があります。

MSDN の例から

 protected void UploadButton_Click(object sender, EventArgs e)
{
    // Save the uploaded file to an "Uploads" directory
    // that already exists in the file system of the 
    // currently executing ASP.NET application.  
    // Creating an "Uploads" directory isolates uploaded 
    // files in a separate directory. This helps prevent
    // users from overwriting existing application files by
    // uploading files with names like "Web.config".
    string saveDir = @"\Uploads\";

    // Get the physical file system path for the currently
    // executing application.
    string appPath = Request.PhysicalApplicationPath;

    // Before attempting to save the file, verify
    // that the FileUpload control contains a file.
    if (FileUpload1.HasFile)
    {
        string savePath = appPath + saveDir +
            Server.HtmlEncode(FileUpload1.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 that the file was uploaded successfully.
        UploadStatusLabel.Text = "Your file was uploaded successfully.";

    }
    else
    {
        // Notify the user that a file was not uploaded.
        UploadStatusLabel.Text = "You did not specify a file to upload.";   
    }

彼らよりもうまく説明できるとは思えません...

于 2013-04-03T15:47:52.707 に答える