Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

HttpContext Wierd Values

Posted on 2013-01-02
6
Medium Priority
?
363 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
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Lync server 2013 or Skype for business Backup Service Error ID 4049 – After File Share Migration
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…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

636 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