Home > Ask the Microsoft .Net Development Experts > ASP.NET and Web Development Questions & Answers > Redirecting results to a text file
Ask The Win Development Expert: Questions & Answers
EMAIL THIS

Redirecting results to a text file

Daniel Cazzulino EXPERT RESPONSE FROM: Daniel Cazzulino

Pose a Question
Other Win Development Categories
Meet all Win Development Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 25 November 2004
I am programming ASPX pages in C# and I want to redirect the result from a created process to a text file, like:
Process myProcess = new Process();

myProcess.StartInfo.FileName = "cmd.exe";

string a = @"/c echo Y| ping  www.yahoo.com>d:temp.txt";

myProcess.StartInfo.Arguments = a;

myProcess.StartInfo.UseShellExecute=false;

myProcess.StartInfo.RedirectStandardOutput = true;

myProcess.StartInfo.CreateNoWindow = true ;

myProcess.Start();
But it did not work: nothing was written into the file temp.txt and I did not get any error message. Can you help me to find where the problem is?

>
The problem is a lack of permissions to write the target file, which is usually the case for the ASP.NET process identity, unless you increase permissions (i.e. creating an empty file in advance and giving ASP.NET or Everyone full control over it). In your case, I think it's better to avoid writing a file altogether. You can do that using the following code:
ProcessStartInfo info = new ProcessStartInfo(
    "cmd.exe", @"/c echo Y| ping  localhost");
info.UseShellExecute = false;
info.RedirectStandardOutput = true;
info.CreateNoWindow = true ;
Process p = Process.Start(info);

string output = p.StandardOutput.ReadToEnd();
Response.Write(output);
Writing files (fixed file names, specially) in an ASP.NET application is not a good idea as multiple threads can try to write the same file simultaneously.


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
ASP.NET and Web Development
Top ASP.NET expert advice from Danny Cazzulino
Access VB .NET Windows control on client side
Drop down list server control creates error message
Take care with InitializeComponent
Calling via command prompt from ASP.NET
Screen capturing
How to retrieve the MAC address of a client using ASP.NET
How to sort a dropdown list in ASP.NET
Accessing session variables in different pages
Automatically closing a .exe

ASP.NET
Top ASP.NET expert advice from Danny Cazzulino
Access VB .NET Windows control on client side
Drop down list server control creates error message
How to retrieve the MAC address of a client using ASP.NET
How to sort a dropdown list in ASP.NET
Accessing session variables in different pages
Automatically closing a .exe
Accessing a control on an independent application
Checking input by character to verify validity
Referencing an old Crystal Reports version

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Windows Development - White Papers, News and Expert Advice
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts