tags:

views:

195

answers:

1

hi, strPath= c:\images\gallery\add.gif now i need to rename this file name add.gif -->thumb1.gid now i should write one comman method whateverthe file name be we need to replace that name with this
string strfilename = "thumb"

**Result thum.gif

strPath= c:\images\gallery\thum.gif** thank you

+3  A: 

You have several problems; looking up the value in the XML file, and renaming the file.

To look up the number corresponding to Gallery2 or whatever, I would recommend having a look at StackOverflow question 1169398 which explains how to look up nodes/values in an XML file.

To rename a file in .NET, use something like this:

using System.IO;

FileInfo fi = new FileInfo("c:\\images\\gallery\\add.gif");
if (fi.Exists)
{
    fi.MoveTo("c:\\images\\gallery\\thumb3.gif");
}

Of course, you would use string variables instead of string literals for the paths.

That should give you enough information to piece it together and solve your particular lookup-rename problem.

NeilDurant
Don't use File.Exists() like that. Just wrap it in a try/catch instead. You have to use the try/catch anyway, because the file system is volatile, and things could change between when you check .Exists() and when you call .MoveTo(), so you may as well just skip the Exists() check.
Joel Coehoorn
Very good point, thanks Joel :)
NeilDurant