Link to home
Start Free TrialLog in
Avatar of johno1000
johno1000

asked on

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

Avatar of johno1000
johno1000

ASKER

Just type the location in the URL bar and I got a HTTP 403 error
Have you tried Process.Start(Server.MapPath("~/Attachments/" + fileName)) ?
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

@ 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

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

Please clarify
What is Attachments. Is it virtual directory?

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

http://itsuit.it.ac.uk/web/Attachments/634021777431309205Mine.doc
string path = @"\Attachments\ + File";
Do not gives you concatenation. You placed quotes in wrong place.
ASKER CERTIFIED SOLUTION
Avatar of lazyberezovsky
lazyberezovsky
Flag of Belarus image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes. lazyberezovsky comment #31203912 will match your requirement.
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;