Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a Document Library with column type Hyperlink or Picture (Signature).

How to insert (Signature) into your Word document?

I find this link for insert Picture into word.

I problem is : How do insert the internet picture(url) in word ?

I use this code

  ImagePart imagePart = mainPart.AddImagePart(ImagePartType.Jpeg);
  //Send an HTTP request and get the image at the URL as an HTTP response
  HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(fileName);
   WebResponse myResp = myReq.GetResponse();

  //Get a stream from the webresponse
  Stream stream = myResp.GetResponseStream();

  imagePart.FeedData(stream);

but i get error

The remote server returned an error: (401) Unauthorized

share|improve this question
    
had you try to specify a internet URL? the problem can be the machine's security settings –  Salvatore Di Fazio Apr 9 '12 at 5:58
    
I do not know how use insert images from the internet into a Word! –  ar.gorgin Apr 9 '12 at 6:22
    
did you try to use something like this: WebClient Client = new WebClient (); Client.DownloadFile("i.stackoverflow.com/Content/Img/stackoverflow-logo-250.png";, @"C:\folder\stackoverflowlogo.png"); Than add the image from your local path? –  Salvatore Di Fazio Apr 9 '12 at 6:28
    
I don't save image in local path. –  ar.gorgin Apr 9 '12 at 6:32
    
can you save it in local path or not? –  Salvatore Di Fazio Apr 9 '12 at 6:55
show 5 more comments

1 Answer

up vote 0 down vote accepted

I add Credentials for HttpWebRequest .

myReq.UseDefaultCredentials = true;
myReq.PreAuthenticate = true;
myReq.Credentials = CredentialCache.DefaultCredentials;

It is work for me :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.