Web.config:指定文件位置

时间:2016-07-19 02:43:39

标签: asp.net vb.net file-upload web-config filepath

我的web.config有问题,我是新手。而且我不知道如何将文件路径放入btn_uploadFile_Click。这是我的web.config文件路径

  <appSettings>
    <add key="IncidentPath" value="C:\Netserve\Incident\"/>
    <add key="ContractPath" value="C:\Netserve\Contract\"/>
  </appSettings>

和vb代码。我不想使用savePath变量。我想从web.config中检索文件夹路径,之后我想检查路径是否有效。那可能吗?怎么做?

Protected Sub btn_uploadFile_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_uploadFile.Click
        Try
            Dim savePath As String = "c:\Netserve\Incident\" & Me.in01_txt_incidentNo.Text & "\"


            If Not IO.Directory.Exists(savePath) Then
                IO.Directory.CreateDirectory(savePath)
            End If
            If (FileUpload1.HasFile) Then
                ' Get the name of the file to upload.
                Dim fileName As String = FileUpload1.FileName

                While IO.File.Exists(savePath & fileName)
                    fileName = "C" & fileName
                End While


                savePath += fileName

                FileUpload1.SaveAs(savePath)

                saveFiletoDB(savePath, fileName)
            Else
                ' Notify the user that a file was not uploaded.
                ShareVar.dd_error("You did not specify a file to upload.")
            End If
        Catch ex As Exception
            ShareVar.dd_error(ex.Message)
        End Try
    End Sub 

1 个答案:

答案 0 :(得分:0)

  1. 向您的项目添加对_bstr_t description(L"naughty"); errorInfo->GetDescription(&description); 的引用(如果尚未添加),并将comutil.h添加到后面代码中的imports语句中。

    < / LI>
  2. 使用ConfigurationManager.AppSettings读取.config文件的System.Configuration.dll部分中的值

相关问题