Solved

Redirecting to text file

Posted on 2016-09-07
11
36 Views
Last Modified: 2016-09-08
Why is this code not opening up a new window with the text file.  I've confirmed the file exists.  The problem seems to be with the response. write statement.

string UserFile = Page.User.Identity.Name.ToString();
                                        UserFile = UserFile.Replace(".", "");
                                        using (StreamWriter sw = new StreamWriter(DownloadDir + "gc\\Downloads\\" + UserFile + ".txt"))
                                        {
                                            foreach (DataColumn dc in ds.Tables["InputParameters"].Columns)
                                            {
                                                sw.Write(dc.ColumnName + "|");
                                            }
                                            sw.WriteLine("");
                                           
                                            foreach (DataRow dr in ds.Tables["InputParameters"].Rows)
                                            {
                                                ColCt = 0;
                                                foreach (DataColumn dc in ds.Tables["InputParameters"].Columns)
                                                {
                                                    sw.Write(dr[ColCt].ToString() + "|");

                                                    ColCt += 1;
                                                }
                                                sw.WriteLine("");
                                            }
                                    }

                                        Response.ContentType = "text/plain";
                                        Response.Write("<script>window.open('" + WebPath + "DS_SDI/gc/Downloads/" + UserFile + ".txt" + "','_blank')</script>");
                                        Response.End();

Open in new window

0
Comment
Question by:AlHal2
[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
  • 5
  • 3
11 Comments
 
LVL 25

Expert Comment

by:SStory
ID: 41788149
I assume there is no pop-up blocker and that javascript is enabled on the browser? If so, try hardcoding the javascript to make sure it works that way first.
0
 
LVL 15

Expert Comment

by:WalkaboutTigger
ID: 41788197
Why do these constructs look different?

(StreamWriter sw = new StreamWriter(DownloadDir + "gc\\Downloads\\" + UserFile + ".txt"))

Open in new window

Response.Write("<script>window.open('" + WebPath + "DS_SDI/gc/Downloads/" + UserFile + ".txt" + "','_blank')</script>");

Open in new window


Is DS_SDI a virtual directory published on the webserver pointing to DownloadDir?

Also, as SStory points out, ensure no popup blockers are enabled, use a static construct for folder in both locations to ensure they're working as expected.

Verify spelling and case of virtual directory in the code matches what is published on the server.  Case makes a difference in this situation, for the directory name, file name, and extension.
0
 

Author Comment

by:AlHal2
ID: 41789252
I tried hardcoding the javascript.  It failed.
I put the JavaScript into a text file which I saved as an html file.  It worked.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:AlHal2
ID: 41789258
Pup up blocker is off.
0
 
LVL 25

Expert Comment

by:SStory
ID: 41789466
OK. Good. That is the way to debug it. Now you need to let the page generate the javascript, and in the browser do view source and see if that javascript looks like what you put in the html page exactly or if you missed anything.  Please post both the .HTML file and the "view source" output from the dynamically generated page.
0
 

Accepted Solution

by:
AlHal2 earned 0 total points
ID: 41789777
Thanks for your help.  I circumvented the problem by using blat.exe to email the relevant file.
0
 

Author Comment

by:AlHal2
ID: 41790129
I've requested that this question be closed as follows:

Accepted answer: 0 points for AlHal2's comment #a41789777

for the following reason:

Thanks for your help.  I circumvented the problem by using blat.exe to email the relevant file.
0
 
LVL 25

Expert Comment

by:SStory
ID: 41790130
AlHal2: I'm glad you solved your problem another way. Since, "how do I email a file via the command-line?" was not part of your question I don't see how it can be accepted as the answer.  I'm not sure that we have yet arrived at the solution, but just saying..
0
 

Author Comment

by:AlHal2
ID: 41790210
OK. Giving you points for effort.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

705 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