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
Solved

Redirecting to text file

Posted on 2016-09-07
11
33 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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