Process.Start doenst work now application is live? C# asp.net - Opening folder

Hi, I have an upload function which saves attchments to a folder. I am trying to access the uploaded attachments using Process.Start to open them.

This worked fine when local but now its on the web server it no longer works. Im presuming it becuase of Process.Start. My issues is that I get the error that it cant locate the folder/file but im sure its mapped properly.

Any ideas why its doing this or how to overcome it?

Thanks
}

string Location = "~\\Attachments\\";
        
string File = lblLink.Text;
     
Process.Start(Location + File);
        
	   //"file:///W:/Attachments"
            //lblLink.Text = Location + File;
            //Debug.Write (Location + File);
            //Console.WriteLine(Location + File);
            //Console.ReadLine();
        }

Open in new window

johno1000Asked:
Who is Participating?
 
lazyberezovskyCommented:
Code below works just fine:
string fileName = "634021777431309205Mine.doc";
string path = Server.MapPath("~/Attachments/" + fileName);
FileInfo file = new FileInfo(path);

if (file.Exists)
{
    Response.Clear();
    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
    Response.AddHeader("Content-Length", file.Length.ToString());
    Response.ContentType = "application/octet-stream";
    Response.WriteFile(file.FullName);
    Response.End();
}

Open in new window

0
 
johno1000Author Commented:
Just type the location in the URL bar and I got a HTTP 403 error
0
 
lazyberezovskyCommented:
Have you tried Process.Start(Server.MapPath("~/Attachments/" + fileName)) ?
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
rajapandian_81Commented:
Hi,

Process.Start will not open file in client machine.

Try below code:

string path = "File Name with Path Here";
System.IO.FileInfo file = new System.IO.FileInfo(path);

if (file.Exists)
{
   Response.Clear();
   Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
   Response.AddHeader("Content-Length", file.Length.ToString());
   Response.ContentType = "application/octet-stream";
   Response.WriteFile(file.FullName);
   Response.End();
}

Open in new window

0
 
johno1000Author Commented:
@ lazyberezovsky: - Yeah I have, no luck with that either.

@rajapandian_81: The file name changes so I cant write the name of it. Can this be done stating the path and a string the contains the file name?

Tired this below but no luck
string path = @"\Attachments\ + File";
        System.IO.FileInfo file = new System.IO.FileInfo(path); 

if (file.Exists) 
{ 
   Response.Clear(); 
   Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name); 
   Response.AddHeader("Content-Length", file.Length.ToString()); 
   Response.ContentType = "application/octet-stream"; 
   Response.WriteFile(file.FullName); 
   Response.End(); 
}

Open in new window

0
 
rajapandian_81Commented:
----> string path = @"\Attachments\ + File";

Please clarify
What is Attachments. Is it virtual directory?

I hope File is string variable.
Try
string path = @"Attachments\" + File;
0
 
johno1000Author Commented:
attachments is the folder in my virutal directory that contains the files
0
 
johno1000Author Commented:
the url address is something like this. It does open the file(s)

http://itsuit.it.ac.uk/web/Attachments/634021777431309205Mine.doc
0
 
lazyberezovskyCommented:
string path = @"\Attachments\ + File";
Do not gives you concatenation. You placed quotes in wrong place.
0
 
rajapandian_81Commented:
Yes. lazyberezovsky comment #31203912 will match your requirement.
0
 
johno1000Author Commented:
Superb, I have been trying to fix this for ages thanks!

I changed string filename to = the string holding the filename so

string filename = File;

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.