Hi,

I have the following string and i will pass the filename and then i want to get the corresponding path...

string url = @" --------------Boundary-00=_BLD1cvEPKmuNkgPvUNY3  Content-Type: text/plain; charset=utf-8; name=footer.txt  Content-Disposition: attachment; filename=\""footer.txt\""  Content-Transfer-Encoding: base64    G:\test\Attach\test\footer.txt  --------------Boundary-00=_BLD1cvEPKmuNkgPvUNY3--  ";

Regex r = new Regex(@"[a-z]:\\([a-z1-9\.\s]+\\)+[a-z1-9\.\s]+\.\w",RegexOptions.IgnoreCase);

string regString = r.Match(url).ToString();

I am able to get the output as :
G:\test\Attach\test\footer.t

In the above url string there maybe a chance that there will be 2 or more attachment codes like the above in the same string. I want to get the path alone like G:\test\Attach\test\ by passing a filename along with extension.

I don't know how to do it? Can someone pls help me out.

Thanks
Raja

Recommended Answers

All 3 Replies

public static string System.Path.GetDirectoryName(string path);

where the path argument contains the fullname: path\filename.ext

public static string System.Path.GetDirectoryName(string path);

where the path argument contains the fullname: path\filename.ext

Hi,

Thanks for the reply.. The string that i posted is just a snippet from the string i will take from an XML file. So i don't think that the above would work.. i tried it..beside i need to get the path from the string only..

Thanks..
Raja

Try it,

Regex r = new Regex(@"[a-z]:\\([a-z1-9\.\s]+\\)+[a-z1-9\.\s]+\.\w+", RegexOptions.IgnoreCase);
        MatchCollection m = r.Matches(url);
        foreach (var t in m){
            Console.WriteLine(t);
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.