Victor Charles
asked on
Help with renaming an xml file using VB.NET
Hi,
How do you remame an xml file located in my application's foler. For example I would like to change NSN.xml to BELNSN.xml.
Thanks,
Victor
How do you remame an xml file located in my application's foler. For example I would like to change NSN.xml to BELNSN.xml.
Thanks,
Victor
ASKER
Hi,
I tried to follow the approach suggested but the syntax is incorrect, any ideas what is the proper syntax?
My.Computer.FileSystem.Ren ameFile((A pplication .StartupPa th + "\LinkFiles\LinkNSN" & Trim(NSN.Text) & ".xml")", (Application.StartupPath + "\LinkFiles\LinkNSN" & Trim(NSN.Text) & ".xml"))
Thanks,
Victor
I tried to follow the approach suggested but the syntax is incorrect, any ideas what is the proper syntax?
My.Computer.FileSystem.Ren
Thanks,
Victor
you rename for the same filename? the first parameter is the current name. the second is the new name. I read twice the same value
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I tried to follow the approach suggested but the syntax is incorrect, any ideas what is the proper syntax?In addition to the comments you've received above, I would suggest employing a bit of strategic Path.Combine and Path.ChangeExtension to alleviate some of the readability issues you have in that bit of code. For example:
Imports System.IO
...
Dim sourceFilename As String = Path.Combine(Application.StartupPath, "\LinkFiles\LinkNSN")
Dim destinFilename As String = Path.Combine(Application.StartupPath, "\LinkFiles\LinkNSN")
sourceFilename = Path.Combine(sourceFilename, Trim(NSN.Text))
sourceFilename = Path.ChangeExtension(sourceFilename, ".xml")
destinFilename= Path.Combine(destinFilename, Trim(NSN.Text))
destinFilename= Path.ChangeExtension(destinFilename, ".xml")
My.Computer.FileSystem.RenameFile(sourceFilename, destinFilename)
ASKER
Hi,
The code below worked but the original xml file is not deleted.
File.Copy(Application.Star tupPath & "\" & "LinkFiles\LinkNSN.xml", Application.StartupPath & "\" & "\LinkFiles\LinkNSN" & Trim(LoginForm1.Ctry.Text) & ".xml", True)
Any ideas why the original file(LinkNSN.xml) is not deleted?
Thanks,
Victor
The code below worked but the original xml file is not deleted.
File.Copy(Application.Star
Any ideas why the original file(LinkNSN.xml) is not deleted?
Thanks,
Victor
because you are doing a copy. use Name instead.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
File.Name does not exist. Move works without True in the code.
Thanks.
Thanks.
ASKER
Thank You.
I meant:
My.Computer.FileSystem.Ren ameFile(Ap plication. StartupPat h & "\" & "LinkFiles\LinkNSN.xml", Application.StartupPath & "\" & "\LinkFiles\LinkNSN" & Trim(LoginForm1.Ctry.Text) & ".xml")
My.Computer.FileSystem.Ren
ASKER
Thank you for the clarification.
ASKER
I tried your latest approach but getting the following error:
Argument 'newName' must be a name, and not a relative or absolute path: 'C:\Users\victor\Documents \Visual Studio 2010\Projects\TEST_XML_New \TESTNSN_X ML\bin\Deb ug\\LinkFi les\LinkNS NBEL.xml'.
Parameter name: newName
How do i solve this error?
Thanks,
C.
Argument 'newName' must be a name, and not a relative or absolute path: 'C:\Users\victor\Documents
Parameter name: newName
How do i solve this error?
Thanks,
C.
the example on http://msdn.microsoft.com/en-us/library/2ce15by3.aspx shows:
My.Computer.FileSystem.Ren ameFile(Ap plication. StartupPat h & "\" & "LinkFiles\LinkNSN.xml", "LinkNSN" & Trim(LoginForm1.Ctry.Text) & ".xml")
My.Computer.FileSystem.Ren
you can use the My.Computer.FileSystem.Ren