0

我编写了一个将数据从 Excel 电子表格上传到表单的函数。从我的电脑测试成功。我将我的 vb.net 代码迁移到了开发服务器,现在我收到了根路径消息。

我的代码适用于其他人编写的现有代码。我不太明白它在做什么,因为没有评论,而且我是编程新手。

我的想法是代码的第一部分正在寻找用户提交的文件的路径(IF 部分),而代码的第二部分(在 ELSE 部分中)是——实际上并不确定,因为代码似乎是多余的. 我知道我们在服务器上有一个临时文件夹。了解代码在做什么会很有帮助,这样我就可以弄清楚服务器路径的放置位置。有人可以评论代码以帮助我理解吗?

If WebPath.Contains("localhost") Then
    FilePath = Path.Combine("c:\open", FileName)
    FileUpload1.SaveAs(FilePath)
Else
    Dim FolderPath As String = ConfigurationManager.AppSettings("FolderPath")
    FilePath = FolderPath & FileName
    FileUpload1.SaveAs(FilePath)
End If
4

2 回答 2

2

据我了解:

' localhost usually refers to development environment
If WebPath.Contains("localhost") Then
    FilePath = Path.Combine("c:\open", FileName)
    FileUpload1.SaveAs(FilePath)
' So if it is not localhost, the code will goes here
Else
    ' The code is trying to grab the FolderPath value from the .config file
    ' For example: web.config file
    ' Here is the example of how it may looks inside the web.config file
    ' <?xml version="1.0" encoding="utf-8" ?>
    '  <configuration>
    '   <appSettings>
    '    <add key="FolderPath" value="filepath"/>
    '   </appSettings>
    '  </configuration>
    ' So, if you want to change the location, change the "filepath" value in the web.config file
    Dim FolderPath As String = ConfigurationManager.AppSettings("FolderPath")
    ' Also use Path.Combine over here
    FilePath = Path.Combine(FolderPath,FileName)
    FileUpload1.SaveAs(FilePath)
End If
于 2018-02-01T15:34:21.273 回答
0

两个输入,WebPath 和 FileName

WebPath 在其中的任何位置包含单词“localhost”,然后将文件保存到“c:\open\”

否则从应用程序配置设置“FolderPath”中读取文件夹名称并将文件存储在

确实,只需使用调试器单步执行代码,看看是做什么的

于 2018-02-01T16:33:57.693 回答