Click here to Skip to main content
13,096,399 members (56,174 online)
Rate this:
Please Sign up or sign in to vote.
See more: , +
hi friends

here i am posting my code please guys suggest me where i was wrong
this code reads the response stream for .doc files for .rtf files it gives "Document server is busy please try after some time".
please help me guys

HttpWebResponse response = null;
HttpWebRequest request = null;
CookieContainer container = new CookieContainer();
//container contains all the cookies related to my site
 request = (HttpWebRequest)WebRequest.Create("");
                request.CookieContainer = new CookieContainer();
                request.CookieContainer = container;
                request.Method = "GET";
                request.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore);
                request.KeepAlive = false;
                request.Timeout = 5000;
                request.Proxy = null;
                request.ContentType = "application/ms-word";
                request.Credentials = new NetworkCredential("admin", "password");
                using (response = (HttpWebResponse)request.GetResponse())

                    readStream = response.GetResponseStream();
                    contentType = response.ContentType;
                    path = "E:\\Files";
string extension=string.empty;
                   if (contentType == "text/html")
                        if (request != null)
                            request = null;
                        return false;
                        if (contentType == "application/rtf")
                            extension = ".rtf";
                            extension = ".doc";

                        FileStream writeStream = new FileStream(path + extension, FileMode.Create, FileAccess.Write);
                        ReadWriteStream(readStream, writeStream);//creates the file and writes data to file.
                        if (request != null)
                            request = null;
                        return true;

in the above example .doc files contains data after downloading. but for .rtf files I am getting "Document server is busy please try after some time" message rather than the actual content.

suppose if i copy paste the url in browser .rtf file contains data..
Please help me guys
Posted 11-Apr-12 1:37am
Updated 1-Sep-12 18:23pm
ryanb31 11-Apr-12 10:28am
Sounds like your session is timing out. Also, unless someone else who reads this has had the exact same problem I doubt anyone can help unless you share some code and more details.
hitech_ssc 12-Apr-12 1:27am
there is no session time out still am logged in
hitech_s 28-Aug-12 14:18pm
may i know the guys who down voted and why ?
you should give proper reason to down vote something . please let me know...don't be think in negative way and don't make people sad.
mark merrens 28-Aug-12 15:45pm
Saying don't make people sad will get you down-voted around here.

You've probably been down-voted because you have asked a question without providing sufficient information. None of us (that I'm aware of) are telepathic so there is no way we can know what is going on without some code.
Christian Amado 28-Aug-12 17:03pm
Read over and over again, but I don't understand your question. Can we see some code here?
Dasaradhi_r 29-Aug-12 3:02am
The question is quite fine for me.
If it is opening up in browser, ideally it should work with web browser control in windows application also. Please let me know the below details:
1) What is the size and other details of the document for which you are having issues with download?
2) In your web application is there any config setting related to this?
3) Are there are any specific settings you set for browser control in your win app?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

static public byte[] GetBytesFromUrl(string url)
        byte[] b;
        HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create(url);
        WebResponse myResp = myReq.GetResponse();
        Stream stream = myResp.GetResponseStream();
        //int i;
        using (BinaryReader br = new BinaryReader(stream))
            //i = (int)(stream.Length);
            b = br.ReadBytes(500000);
        return b;
    static public void WriteBytesToFile(string fileName, byte[] content)
        FileStream fs = new FileStream(fileName, FileMode.Create);
        BinaryWriter w = new BinaryWriter(fs);

private void getDocument(string url )
       string DestinationPath = Server.MapPath("targetdocumentspath");
       string filename = url.Substring(url.LastIndexOf('/') + 1);
       byte[] bytes = GetBytesFromUrl(url);
       WriteBytesToFile(DestinationPath + "/" + filename, bytes);       
Dasaradhi_r 29-Aug-12 13:57pm
Your code snippet requires, Url to be provided.
Just curious to know, how Url of link can be picked up from a web browser control?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 19 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100