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

x
?
Solved

Redirecting to text file

Posted on 2016-09-07
11
Medium Priority
?
39 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
Technology Partners: 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!

 

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

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.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

618 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