Search code examples
c#.net.net-2.0

How to change extension of string path in C#?


Below is my string value

string strFile = @"http://login.com/Uploads/g05fgxeto4dvsf5531yb3l45_16_8_2011_1_25_37.doc";

And I need to replace this file path value by

http://login.com/Uploads/g05fgxeto4dvsf5531yb3l45_16_8_2011_1_25_37.pdf

Thanks.


Solution

  • string strFile = @"http://login.contentraven.com/Uploads/g05fgxeto4dvsf5531yb3l45_16_8_2011_1_25_37.DOC";
    
    string strTemp = Path.GetExtension(strFile).ToLower();
    
    if (strTemp==".doc")
    {
        strFile = Path.ChangeExtension(strFile, "pdf");
    }