views:

36

answers:

1

I have a document that I have included in my VS 2010 solution. It is in a folder called "MyFolder" the file itself is called "MyDoc.docx". I've tried the following ways to open the file but none work:

Stream s = File.OpenRead("/MyFolder/MyDoc.docx");

and

Stream s = File.OpenRead("MyFolder/MyDoc.docx");

and

Stream s = File.OpenRead("~/MyFolder/MyDoc.docx");

What is the proper path for this file?

+6  A: 
using (var s = File.OpenRead(Server.MapPath("~/MyFolder/MyDoc.docx")))
{
    ...
}

where ~ indicates the site root. Also make sure you grant the account your site is running under read permissions to this folder.

Darin Dimitrov
If a .docx file is plain text, someone's abusing file extensions. ".docx" is the extension for Word 2007 documents, which are basically zip files with XML and other stuff inside.
cHao
It's actually being used by a third party software called Aspose.
Abe Miessler
@cHao, oh my, you are totally right!!! I didn't even look at the extension. Removing this aberration from my post :-) Thanks for noticing.
Darin Dimitrov