0

I have written a function to upload data from an excel spreadsheet to a form. Testing from my computer was successful. I migrated my vb.net code to the dev server and now I'm getting a rooted path message.

My code works with existing code written by someone else. I don't quite understand exactly what it is doing because there's no comments and I'm new to programming.

My thought is the first section of code is looking for the path of the file being submitted by the user (the IF section) and the second section of code (in the ELSE section) is -- not really sure actually as the code seems redundant. I do know we have a temp folder on the server. It would be helpful to understand what the code is doing so I can figure out where to put the server path. Can someone comment on the code to help me understand?

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
MT0
  • 86,097
  • 7
  • 42
  • 90
IM404
  • 3
  • 2
  • and this has what to do with oracle? – pm100 Feb 01 '18 at 16:29
  • We don't put "solved" in titles. Select an answer below or post your own. – LarsTech Feb 01 '18 at 21:18
  • Thanks for letting me know about not putting solved in the title. I've seen that with prior post and that I was suppose to do that to keep others from adding solutions. Much appreciation! – IM404 Feb 02 '18 at 15:16

2 Answers2

2

From my understanding:

' 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
Naim Jamalludin
  • 125
  • 4
  • 13
  • Naim, thank you for the comments. I really appreciate it. I found the issue is that "FolderPath" in my web.config file was not defined correctly. Correcting the path to the temp directory resolved the issue. Boom! Yay! :D – IM404 Feb 01 '18 at 20:49
  • @IM404 Glad to hear that. You can choose my solution as the preferred answer and it will close the question. Thank you. – Naim Jamalludin Feb 02 '18 at 01:07
  • Thank you for the tips. This is my first post on stackoverflow. I found the check mark and selected your answer as the resolution. – IM404 Feb 02 '18 at 15:15
0

two inputs, WebPath and FileName

the the WebPath contains the word "localhost" anywhere in it then save the file to "c:\open\"

else read a folder name from the app config setting "FolderPath" and store the file in

Bu really, just step through the code with a debugger and see what is does

pm100
  • 32,399
  • 19
  • 69
  • 124