Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening a File on the Server Directly

Status
Not open for further replies.

Genimuse

Programmer
Joined
May 15, 2003
Messages
1,797
Location
US
Ok, in response to a user submitting a form I've managed to create an Excel file on the intranet server, in a "publicly"-accessible directory. What I have managed is to, via an ADODB stream, sent the file to the user, so things come off pretty seamless: fill out the form, click the button, get a dialog asking if you want to open or save the spreadsheet.

But, what is of course happening is the user isn't opening the file on the server, they're being sent a completely different copy of the file (with a "[1]" in the name), which if they choose to open, modify, and save, will just end up in their temp internet files directory (which they can't easily tell). If they later go to open it on the server, it won't (of course) have any of their changes.

So, does anyone know of any kind of headers or or client-side VBScript or what-have-you that I can send after generating the spreadsheet that will actually tell the browser to open that exact file on the server? It's easy enough to provide a page with a link to the file that actually opens the real file, but I want the seamlessness of submitting the form and getting the real file instantly in response.
 

Link to the UNC path of the file rather than streaming over HTTP, then as long as the necessary permission / networking is in place (which it should be if they can access the file normally) the user will open up the server instance, and lock/save the file as normal.

e.g.

\\myserver\myshare\mypath\myexcelfile.xls

Use Response.Redirect from the ASP page to this file.

Alternatively you could look into WebDAV, though this will also require some config changes to your IIS server.




A smile is worth a thousand kind words. So smile, it's easy! :-)
 
A web server responds to requests for files by sending a copy. If you want to actually open the file then, like damber suggested, you'll need to make an end run around the web server and use the webserver machine as a plain network file server... and the user will need permission on the file because the interaction will not take place under the web server's security context (ie: not IUSR_MachineName)
 
I originally tried Response.Redirecting to the file, but it won't open that in Excel, instead opening it inside the browser.

And Sheco, "A web server responds to requests for files by sending a copy." Great point, very obvious but I wasn't thinking of it that way, thanks.
 
I've seen suggestions that if I point the user to a shortcut to the file (a .lnk file), then it will always open it in the application instead of within the browser.

So does anyone know a way to create a shortcut within ASP? I've seen some shell scripts that do it, but I don't think I have a way of getting one to run in ASP, do I?
 
And, answering my own question (sorry), this works like a champ:
Code:
<%
[COLOR=gray]'First write out the file
'Your code here

'Now create a shortcut to the spreadsheet[/color]
Dim objWshShell, objShortcut
Set objWshShell = CreateObject("WScript.Shell")
Set objShortcut = objWshShell.CreateShortcut(strDrive & strPath & strFileName & ".lnk")
objShortcut.TargetPath = strDrive & strPath & strFileName & ".xls"
objShortcut.Save

[COLOR=gray]'Finally, redirect the user to the shortcut[/color]
Response.Redirect("file:" & strServer & strPath & strFileName & ".lnk")
%>
Sweet and simple. Wish there was an article that described how to do this out there, but enough Googling and messing around did the trick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top