views:

762

answers:

8

I'm trying to add an image to a generated html word document that is embedded in a classic ASP page. The code looks something like this:

<%
    Response.ContentType = "application/msword"    
%>

<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word">

...

<v:shape id="_x0000_s1030" type="#_x0000_t75" style='position:absolute;
 left:0;text-align:left;margin-left:0;margin-top:17.95pt;width:7in;height:116.85pt;
 z-index:2;mso-position-horizontal:center;mso-position-horizontal-relative:page;
 mso-position-vertical-relative:page'>
 <v:imagedata src="http://xxx/image001.gif" o:title="image001"/>
 <w:wrap anchorx="page" anchory="page"/>
 <w:anchorlock/>
</v:shape><![endif]--><![if !vml]><span style='mso-ignore:vglayout;position:
absolute;z-index:0;left:0px;margin-left:0px;margin-top:24px;width:672px;
height:156px'><img width=672 height=156
src="http://xxx/image001.gif" v:shapes="_x0000_s1030"></span><![endif]>

The image URL is correct and can be viewed through a browser, however when the word document opens, the image has a red x, with the error message:

The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may be corrupted. Restart your computer, and then open the file again. If the red x still appears, you may have to delete the image and then insert it again.

If i copy the html code and try to open the word document on my local machine, it displays the image correctly. It just doesn't work when retrieving the document from the server. This happens for any images I try to add. Is there another way to add images to html-generated word documents that can be output from an asp page?

Thanks.

Update:

Something that I've noticed is that when copying the word doc code from the asp page, pasting it into a file and renaming it as a word doc, I get this prompt when opening it:

Some of the files in this Web page aren't in the expected location. Do you want to download them anyway? If you're sure the Web Page is from a trusted source, click Yes.

If I click Yes, the image displays fine, if I click No, I get the same error as I described above. I'm thinking that because the word doc is coming from an ASP page, it is defaulting the security setting to not display external items. I've tried adding the site URL (it is a local intranet site) to my trusted sites and as a trusted location in word, but still no luck.

A: 

Is all that code generated by Word 2007, or are you adding code by hand? It's interesting that the img tag doesn't have a slash to close it.

action_ben
I didn't write the code, but I assume it was generated by word (probably an older version as this is quite an old application).
spiderdijon
A: 

I know its a silly mistake, but did you make sure to put the image in the right place so that it can be accessed by the web page? If you just type in the http://xxx/image001.gif url into your browser, does the image appear? If not, I would say thats your problem.

Russell Leggett
The url is definitely correct.
spiderdijon
A: 

Make sure the image's URL (location) is correct and add a slash. If it still doesn't work, check if any other images from the same directory can display. If they do then re-upload the image and try again. If other images don't display and if you're sure that the URL is correct, then try editing the read permissions on the image directory and the images. I can't imagine that it could be caused by permissions though.

Unless there's a very specific reason to generate the HTML in MS Word, I'd advise you not to do it. Even for somebody who never saw HTML or CSS before, they're both very simple and tidy to learn and can produce much better results than MS Word.

Koroviev
No other images work, I've even tried images on another server with external URLs. After playing with the permission settings, this also doesn't seem to be the problem.
spiderdijon
A: 

Is Word 2007 allowed to access the internet? Maybe there's a firewall rule blocking it?

Pekka
Disabled the firewall, same issue.
spiderdijon
+1  A: 

You could try removing the o:title tag. I've found that if that tag is there word tries to embed the image, but will only do so if it is in the proper location. By removing the o:title tag, word just treats it as a link.

Matt
Fantastic! That works, thanks.
spiderdijon
A: 

Did you solve the problem? I have run into the same issue. No clue how to resolve it!

Debdoot
Yes, see Matt's post above about removing the o:title tag.
spiderdijon
A: 

I have the same problem in Word 2003. And removing the o:title section does not work. I actually would like to embed the image in the word document. Is there any solution for Word 2003?

Thank you.

Impulse
A: 

Go into Options, Web Options (which might be under Advanced), uncheck "Rely on VML for displaying graphics in browsers"

scrungus