Question : How do I update file, save to new location and keep original file as is using Visual Basic 2008?

Scenario:

We have a variety of HTML files within their own folders.  

Here is an example (app1, app2 and app3 are just generic names.  The actual folder names vary)

C:\inetpub\v5\eLetters\app1\app1.html
C:\inetpub\v5\eLetters\app2\subapp2\app2.html
C:\inetpub\v5\eLetters\app3\app3.html

NOTE: C:\inetpub\v5\eLetters\ will always be the beginning directory path.

We have 3 servers in which these html files will be placed.

Server 1 is the development server where we develop the HTML files

Server 2 is the Quality Assurance Testing server where these HTML files will be tested for accuracy

Server 3 is the Production server where the HTML files will be in production

Goal:

A basic program has been created where the user can select the folder where the HTML resides.  The HTML file will be listed in the list box along with the directory location of the file.  The user will then be able to select the server they want the HTML file to be saved to (once they select the server the IP Address within the HTML file will be updated with that server’s IP Address)

If the file exists on that file then overwrite that file.

 
Screenshot of program
329070
 


Challenge:

I am able to update the IP Address within the HTML file the user selected with the IP Address based on the server the user selected.  I also am able to write to that HTML file and save it with the following code:

Try
Dim sWrite As System.IO.StreamWriter = New IO.StreamWriter(lstHTMLFiles.Items.Item(i).ToString)
         'Write new code to HTML File, Save File and then close file.
          sWrite.Write(rtfNewCode.Text)
          sWrite.Close()
Catch ex As Exception
End Try

What I would like to do is:

Open the HTML file that is listed
Change the IP Address within the HTML file
Save the file to \\servername\v5\eLetters\nameoffolder\nameofhtml.html
      If file exists then overwrite file
      Note: I can hard code \\servername\v5\eLetters\
What I would like to do is capture the next folder(s) name and html file name with extension and add it as a string to the end of \\servername\v5\eLetters\
Keep the HTML file that was originally listed as is (it was just selected)
      Note: I only want the updated HTML file to be saved to the selected server.

I believe we will only be moving one html file at a time, but we might be moving several html files at one time.  

Should I use an If then statement?

If rbtnServer1.checked = True Then
      Write file to this location
Elseif rbtnServer2.checked = True then
      Write file to this location
Elseif rbtnServer2.checked = True then
      Write file to this location Any ideas would be great.  
End if

The challenge I’m having is how to capture the rest of the path after c:\inetpub\v5\eLetters\ placing that into a string and then saving the updated HTML file to the server selected and keeping the HTML that was selected as is.

Any ideas would be great.
 

Answer : How do I update file, save to new location and keep original file as is using Visual Basic 2008?

If I understand you correctly whant you want is to get the
"app1\app1.html" from C:\inetpub\v5\eLetters\app1\app1.html
and
app2\subapp2\app2.html from C:\inetpub\v5\eLetters\app2\subapp2\app2.html
and
app3\app3.html C:\inetpub\v5\eLetters\app3\app3.html

Right?

If that is the case then use the code at the bottom this way:

msgbox(ReplaceServerFilePath("lstHTMLFiles.Items.Item(i).ToString", "\\servername\v5\eLetters"))




1:
2:
3:
4:
Private Function ReplaceServerFilePath(Byval OldServerFilePath as string, Byval NewServerFilePath) as string
Dim ServerFilePath as string = oldServerFilePath.Replace("C:\inetpub\v5\eLetters",string.empty)
Return NewServerFilePath & ServerFilePath
End Function 
Random Solutions  
 
programming4us programming4us