[英]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
在您的項目中添加對System.Configuration.dll
的引用(如果尚未添加),然后在后面的代碼中將Imports System.Configuration
添加到您的import語句中。
使用ConfigurationManager.AppSettings從.config文件的<appSettings>
部分讀取值
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.