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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.