0

I may be going about this the wrong way, but in the website component of my Silverlight app I added some docx files and they are not available when publishing to IIS 7.5. In my dev environment it works great and I can reference the docx files. Each docx file has a build action of 'content' and Copy to Output Directory is set to 'copy always'. When I build the solution, I can see the docx files on my local dev machine in the appropriate folders. When I publish to IIS, the docx files are nowhere to found in the folder structure containing the website on the web server. I tried manually copying the docx files to the web server, but my app still cannot see them.

Is there a better way for my docx files to hitch a ride with my app when I publish to IIS?

4

1 回答 1

1

I wasn't able to figure out how to get the docx files to copy during a publish, but I found a workaround. If you change the build action to embed, you can then reference the files in code. Here is Microsoft's how-to for embedding:

http://support.microsoft.com/kb/319292

To reference a file, use this:

// The Reporting.Web part is my namespace. Everything here is case sensitive!
string template = "Reporting.Web.PerfRevH1.docx";
Assembly loader = Assembly.GetExecutingAssembly();
var rawstream = loader.GetManifestResourceStream(template);
byte[] byteArray = rawstream.ReadToEnd();

To read the stream into a byte array, I used an extension method found here in this SO question: How to convert an Stream into a byte[] in C#?

于 2013-06-24T17:26:15.530 回答