Solved

Redirecting to text file

Posted on 2016-09-07
11
28 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
  • 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
 

Author Comment

by:AlHal2
ID: 41789258
Pup up blocker is off.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now