Opening Word Document in Browser Error: could not find a path in ASP.Net

Last Reply 11 months ago By dharmendr

Posted 11 months ago

Dear All,

i'm following the below link 

Display binary Word document from Database in browser using C# and VB.Net in ASP.Net

But i'm getting the error at this line 

File.WriteAllBytes(Server.MapPath("~/Temp/" + fileextension), bytes);

Error message: could not find a path c:\....

Any comments for above

Thanks in advance


Posted 11 months ago

Yes you need to create the Temp folder.

Else you need to add the below code for Create folder if not present.

C#

//If Directory not present, create it.
if (!Directory.Exists(Server.MapPath("~/Temp/")))
{
    Directory.CreateDirectory(Server.MapPath("~/Temp/"));
}

VB.Net

'If Directory not present, create it.
If Not Directory.Exists(Server.MapPath("~/Temp/")) Then
    Directory.CreateDirectory(Server.MapPath("~/Temp/"))
End If