?
Solved

HttpContext Wierd Values

Posted on 2013-01-02
6
Medium Priority
?
356 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
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

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!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

771 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