Open file on local machine

F

Franck

Hi,
got a datagid which fills files paths in hyperlink controls.
The path of these files looks like "\\MyServer\...\MyFile.xxx"

How can I make my asp.net hyperlink control to open its linked file
with the path as param without opening it in a web page ?

I tried Response.redirect(MyFilePath) but it open the file in the web
page (which I do not want).

Thks for help.
 
F

Franck

Yep (if possible... regarding security)... asking user what to do,
open, cancel, save, etc...
 
G

Grant Merwitz

Create a page that'll stream the .doc file to the user.

(It should by default then ask the user weather they want to Open or Save it
Opening it, should open it in word.)

The code will look something like this:

using System.IO;

Response.ClearContent();
Response.ContentType = "application/msword";
Response.WriteFile(MyFilePath ); //this will be like /file/fileiwant.doc
Response.End();
 
F

Franck

The point that the user could insert in the database whatever file he
wants...

If he inserts a path to a file from which the extension is a strange
one... it's over.

Starting to think I'll forbide every files except Office ones and Pdf...
 
E

Eliyahu Goldin

What do you mean by "without opening it in a web page "? That, for example,
a .doc file should open in Microsoft Word?

Eliyahu
 
G

Grant Merwitz

You can also code the page to determine what file type it is by viewing the
extension and setting the ContentType appropriately.

I normall break down the filename to get the extension, then run a swtich on
that extension to set the content type:
If it wasn't one i was prepared for, i'll throw an exception, or write an
error message to the screen

switch (strFileExtension)
{
case ".pdf":
sContentType = "application/pdf";
break;
case ".ppt":
sContentType = "application/x-mspowerpoint";
break;
case ".tif":
sContentType = "image/tiff";
break;
case ".bmp":
sContentType = "image/bmp";
break;
case ".gif":
sContentType = "image/gif";
break;
case ".zip":
sContentType = "application/x-zip-compressed";
break;
case ".xls":
sContentType = "application/vnd.ms-excel";
break;
}

sdf
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top