[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Getting Error message When i try to write bytes to word document and try to open it....

Posted on 2011-10-24
9
Medium Priority
?
243 Views
Last Modified: 2012-05-12
Getting Error message When i try to write bytes to word document and try to open it....then i get error message saying that the file "Name og the file" cannot be opend because it is a problom with the content og the file.....And when i clik the Ok button on the error message i get another error or warning saying that: Found unreadable content in "filename". Do you want to re create content in the document.....

Can any one see what i have done wrong?
private void ReturnDoc(byte[] doc, string filename)
        {
            HttpResponse resp = HttpContext.Current.Response;
            resp.ClearContent();
            resp.ClearHeaders();
            resp.AddHeader("Content-Disposition", "attachment; filename=" + filename + ".docx");
            resp.ContentEncoding = System.Text.Encoding.UTF8;

           // resp.OutputStream.Write(doc, 0, (int)doc.Length);
            //resp.Write(doc);
            //resp.Flush();
            //resp.Close();
            
            //*****************
            resp.Buffer = true;
            resp.BufferOutput = true;
            resp.AddHeader("Content-Length", doc.Length.ToString());
            resp.BinaryWrite(doc);
            resp.Flush();
            resp.Close();


            HttpContext.Current.ApplicationInstance.CompleteRequest();

        }

Open in new window

0
Comment
Question by:Adnan
  • 7
  • 2
9 Comments
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 37017238
Try this

Replace resp.AddHeader("Content-Disposition", "attachment; filename=" + filename + ".docx");

with

resp.AddHeader("Content-Length", new System.IO.FileInfo(" + filename  +".docx").Length);
0
 

Author Comment

by:Adnan
ID: 37017269
hmm something is wrong in your code line...???!
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 37017336
Did you get any error?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Adnan
ID: 37017359
THE BEST OVERLOAD METHOD FOR MATCH FOR'sYSTEM.WEB.HTTPRESPONSE.ADDHEADER(STRING,STRING)' HAS SOME INVALID ARGUMENTS WHEN I PASTE THE LINE IN MY CODE....
0
 

Author Comment

by:Adnan
ID: 37017606
I am facing a strange problem in IE, when I use this type code for transmit the file (PDF,Excel,Word-doc etc.).

When I export a file In IE as an attachment, it asks me OPEN or SAVE. When I click SAVE, it saves but when I click OPEN, the same dialogue appears again and ask me for retry to open...?!! Whats happening here?
0
 

Author Comment

by:Adnan
ID: 37017639
And iam not facing this problom in FireFox...every thing works fine i firefox, i get the file open doc dialog box and i click OK and document opens....but when iam using IE it wont work for some reason.
0
 

Author Comment

by:Adnan
ID: 37023388
i think the fault is here...

when i use this line of code :  resp.AddHeader("Content-Disposition", "attachment; filename=\"Saksliste.docx\"");

 it wont work as i want it to, the browser aske me for open the file "FileName.docx" and when i click on open button it gave me another option to retry and when i click on retry it open the word but gives an error message saying that the file is corrupt or broken.....

and if i change the file name to only filename=\"Saksliste\", then it gives me option to save tyhe document first and then option to click on Open, when i click open it give a open with Dialog box.....

How can i just open the document in word without getting any option to open with.....
0
 

Accepted Solution

by:
Adnan earned 0 total points
ID: 37031133
0
 

Author Closing Comment

by:Adnan
ID: 37055371
I found the solution....follow the link and read...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question