0

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

3
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by __avd
0
public static string System.Path.GetDirectoryName(string path);

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

0
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

Edited by rajaseeth: n/a

0

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);
        }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.