Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

HttpContext Wierd Values

Posted on 2013-01-02
6
Medium Priority
?
365 Views
Last Modified: 2013-01-05
I writing out the content to HTTP response and I’m adding the header type as CSV. The exports works fine in local, QA and staging but in production I see a hex value at the beginning and 0 at the end. Since I’m not able to reproduce the same in local or QA I’m having a hard time debugging this. Have any of you seen this before ?

This is how I’m writing to response stream. The UI makes an http post to the ExportCSV.

                              [HttpPost]
             public void ExportCSV()
             {
HttpContextBase context = HttpContext;
                           context.Response.Clear();
                           context.Response.ContentType = "text/csv";
                           context.Response.AddHeader("Content-Disposition", "attachment; filename=" + "xxx" + Guid.NewGuid().ToString() + ".csv");
            context.Response.Write("XXXXX”);
                          context.Response.End()
}


This is what I’m seeing in the export

22d (Hex value proportional to content length)

Data

0
0
Comment
Question by:optimus376
  • 3
  • 2
6 Comments
 
LVL 11

Assisted Solution

by:MajorBigDeal
MajorBigDeal earned 1000 total points
ID: 38738447
Just a thought, but is the string coming from the same place in production vs the other environments, are the library versions the same, and is the character set UTF-8 in both cases?  

I remember back in my VB6 days I was using a different character set (I'm not sure if it was UCS-2 or UTF-16) but each character required exactly 2 bytes (unlike UTF-8) and my strings had a length parameter in the front, and a zero termination at the end which seems kind of similar to what you are describing.

So if the string is coming from an older version of software than in production vs the other environments, that might account for it.
0
 

Author Comment

by:optimus376
ID: 38738459
Thanks MajorBigDeal. The data is actually coming from UI. The server side just formats the data and returns the reponse as csv. Do you think forcing

Response.ContentType = "text/csv; charset=utf-8"; will help ?
0
 
LVL 23

Accepted Solution

by:
Roopesh Reddy earned 1000 total points
ID: 38739409
Hi,

Is this an MVC application? If yes, then try FileResult - http://msdn.microsoft.com/en-us/library/system.web.mvc.fileresult(v=vs.108).aspx

Moreover, are you providing the full path of the file like this -
filename=" + "xxx" + Guid.NewGuid().ToString() + ".csv" in  context.Response.Write("XXXXX”);

Try this, as suggested in this article - http://www.c-sharpcorner.com/UploadFile/d3e4b1/saving-reading-uploading-downloading-mechanism-of-csv-fil/

Hope it helps u...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:MajorBigDeal
ID: 38739517
It might help, I'm not sure.  One thing that would be good to know is if the difference in in the actual string coming from the UI, or if the difference is being introduced when the string is processed for output.  That would be a big clue as to what is going on.
0
 

Author Comment

by:optimus376
ID: 38745750
I changed the function return type as FileResult and returned a File(stream, filename) and it magically fixed things. THanks :)
0
 

Author Comment

by:optimus376
ID: 38747011
I've requested that this question be closed as follows:

Accepted answer: 0 points for optimus376's comment #a38745750

for the following reason:

Found the solution myself
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Lync server 2013 or Skype for business Backup Service Error ID 4049 – After File Share Migration
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month21 days, 5 hours left to enroll

810 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