簡體   English   中英

Web.config:指定文件位置

[英]Web.config: Specify a file location

我的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. 在您的項目中添加對System.Configuration.dll的引用(如果尚未添加),然后在后面的代碼中將Imports System.Configuration添加到您的import語句中。

  2. 使用ConfigurationManager.AppSettings從.config文件的<appSettings>部分讀取值

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM