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 use this coe for save image in word document.

 System.Net.WebRequest request = System.Net.HttpWebRequest.Create(SPContext.Current.Site.Url);
 request.UseDefaultCredentials = true;
 request.PreAuthenticate = true;
 request.Credentials = CredentialCache.DefaultCredentials;

 System.Net.WebResponse response = request.GetResponse();
 HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(SignAddress);
 myReq.UseDefaultCredentials = true;
 myReq.PreAuthenticate = true;
 myReq.Credentials = CredentialCache.DefaultCredentials;

 WebResponse myResp = myReq.GetResponse();

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

when run this in server, it is work .

but when i run this with internet(ip) i get error :

Trying to use SPWEb object that has been clesed or disposed and is no longer valid.

share|improve this question
add comment

2 Answers 2

There are a few things to try:

  1. Make sure that if you use the IP it is also added into the AAM
  2. When using DEfaultCredentials the machine from which you are trying must be added to the same Domain, otherwise it will never work (e.g. Extranet/Intranet scenarios)
  3. Always check the SPContext is NOT Null (if you just take the example in a Console like this it will never work) - you would need to rely on the Managed Client Object Model or otherwise SPCOntext has no value (example here http://msdn.microsoft.com/en-us/library/ee857094.aspx#SP2010ClientOM_Using_the_Managed_Client_Object_Model). However if this is built into a Application Page or Web Part it should be ok.

Hope it helps, C:\Marius

share|improve this answer
    
I check all, but don't work! –  ar.gorgin May 13 '12 at 4:48
    
instead of using DefaultCredentials try passing the same credentials manually of the user you are logged on with while testing from your server. –  C. Marius - MVP May 13 '12 at 8:39
add comment
up vote 0 down vote accepted

I replace this code for get stream. it is work for me :)

   SPFile Signfile = web.GetFile(SignAddress);
    if (Signfile.Exists)
     {
         stream = Signfile.OpenBinaryStream();
     }
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.