View Full Version : upload, convert, email in asp
kma07
07-02-2010, 02:10 AM
Hey all
I've created a page where the user browses his/hers machine and is able to upload the file onto a server.
Now once it has been uploaded onto the server, I need it to call an external program (that runs a .exe to convert this file) then once it's processed, I need it to send this file to the user's email address (that they have entered)
Any help?
Old Pedant
07-02-2010, 02:27 AM
You may or may not be able to call an external ".exe" program from your ASP code. It depends on settings on the server.
But the process of doing so isn't *too* complex.
Here's a very old article that shows the basics. I *think* it is still valid today:
http://www.4guysfromrolla.com/webtech/102998-1.shtml
The baics of it are simple enough:
Set WShShell = Server.CreateObject("WScript.Shell")
RetCode = WShShell.Run("c:\full\path\to\your.exe " & arguments)
...
NOTE: If you "own" this server, you will have to change the IIS settings to allow execution of external programs. Way back in 1998 when that article was written, such execution was enabled by default. Nowadays, the server ships with that disabled. I'm not an IIS guru, so I don't know where the setting is, offhand, but you should be able to google for it.
kma07
07-05-2010, 05:04 AM
Sorry I'm still new to this,
Here's my code, at the moment I can upload a file to my server, now I need to call a .bat file to run another program
Where do I put the code to run a .bat file?
<%@ Page Language="VB"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>TRANSFER</title>
</head>
<Script Language="VB" RunAt="Server">
Sub Page_Load(Sender as Object, e as EventArgs)
Dim MyPath, MyName As String
' Display the names in C:\ that represent directories.
MyPath = "//my//d$//folders//file//uploads//" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
if MyName="" ' The folder is not there & to be created
MkDir("//my//d$//folders//file//uploads//") 'Folder created
Span2.InnerHtml = "A Folder (////my//d$//folders//file//uploads//) is created at the Page_Load"
end if
End Sub
Sub Upload_Click(Sender as Object, e as EventArgs)
' Display properties of the uploaded file
FileName.InnerHtml = MyFile.PostedFile.FileName
FileContent.InnerHtml = MyFile.PostedFile.ContentType
FileSize.InnerHtml = MyFile.PostedFile.ContentLength
UploadDetails.visible = True
' Let us recover only the file name from its fully qualified path at client
Dim strFileName as string
strFileName = MyFile.PostedFile.FileName
Dim c as string = System.IO.Path.GetFileName(strFileName) ' only the attched file name not its path
' Let us Save uploaded file to server at //my//d$//folders//file//uploads//
Try
MyFile.PostedFile.SaveAs("//my//d$//folders//file//uploads//" + c)
Span1.InnerHtml = "Your File Uploaded Sucessfully at server as : //my//d$//folders//file//uploads//" & c
catch Exp as exception
span1.InnerHtml = "An Error occured. Please check the attached file"
UploadDetails.visible = false
span2.visible=false
End Try
End Sub
</Script>
<Body>
<Font Color="DarkGreen" Face=Helvetica Size=5> <B>ONIX GEISHA TRANSFER</B>
</Font>
<HR Size="2" Color=Black >
<P>
<Form id="Form2" Method="Post" EncType="Multipart/Form-Data" RunAt="Server">
Choose Your File To Upload : <BR>
<Input ID="MyFile" Type="File" RunAt="Server" Size="40"> <BR>
<BR>
<Input id="Submit1" Type="Submit" Value="Upload" OnServerclick="Upload_Click" RunAt="Server">
<P>
<Div ID="UploadDetails" Visible="False" RunAt="Server">
File Name: <Span ID="FileName" RunAt="Server"/> <BR>
File Content: <Span ID="FileContent" RunAt="Server"/>
<BR>
File Size: <Span ID="FileSize" RunAt="Server"/>bytes
<BR></Div>
<Span ID="Span1" Style="Color:Red" RunAt="Server"/>
<Span ID="Span2" Style="Color:Red" RunAt="Server"/>
</P></P>
<HR Size="2" Color=Black>
<form>
</Form>
</Body>
</html>
Old Pedant
07-05-2010, 10:37 PM
Oh, you didn't *SAY* this is ASP.NET! You posted in the ASP forum, not the ASP.NET forum.
Rules are different with ASP.NET. And, in fact, if at all possible you should avoid using an external program. Anything you can do with an external program you *should* be able to do in VB.NET (or C#) coding. But if you must use an external program, it's done completely differently than I showed you. Google for "invoking external executable from ASP.NET".
kma07
07-09-2010, 05:25 AM
oh ok sorry about that!
Thanks Old Pedant
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.