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.
|