[英]Web.config: Specify a file location
I have a problem with web.config, I am a newbie. 我的web.config有问题,我是新手。 And i don't know how to get the filepath into btn_uploadFile_Click. 而且我不知道如何将文件路径放入btn_uploadFile_Click。 Here's my web.config filepath 这是我的web.config文件路径
<appSettings>
<add key="IncidentPath" value="C:\Netserve\Incident\"/>
<add key="ContractPath" value="C:\Netserve\Contract\"/>
</appSettings>
And vb code. 和vb代码。 I don't want to use the savePath variable. 我不想使用savePath变量。 I want to retrieve the folder path from web.config, and after that I want to check whether the path is valid. 我想从web.config中检索文件夹路径,然后再检查路径是否有效。 Is that possible? 那可能吗? How to do that? 怎么做?
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
Add a reference to System.Configuration.dll
to your project (if it's not already added) and add Imports System.Configuration
to your imports statements in the code behind. 在您的项目中添加对System.Configuration.dll
的引用(如果尚未添加),然后在后面的代码中将Imports System.Configuration
添加到您的import语句中。
Use ConfigurationManager.AppSettings to read the values from the <appSettings>
section of the .config file 使用ConfigurationManager.AppSettings从.config文件的<appSettings>
部分读取值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.