Click here to Skip to main content
15,886,199 members
Articles / Web Development / ASP.NET

ASP.NET File Uploader with Overwrite Message

Rate me:
Please Sign up or sign in to vote.
4.42/5 (8 votes)
3 Dec 2008CPOL3 min read 55K   923   42  
Intranet file upload dialog box with overwrite prompt and file archiving.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<HEAD>
<TITLE>File Uploader Dialog Demo</TITLE>
<META http-equiv=content-type content="text/html; charset=ISO-8859-1">
</HEAD>
<BODY>

<script language="JavaScript">

//set variables here

var btestNonIE = false;  //set to false - **** for testing only *****

var sReturnForm = "edit_Content";
var sReturnField = "FileName";
var sUploadFolder = "pending";

//use only one value: [popup, message, none]
//none value will archive without prompting if Archive dir is set
var sOverwritePrompt = "popup"  

// archives old file if value set (regardless of overwrite prompt)
//will also create sub dir if path is more than one level
var sArchiveFolder = "archive/december";
 
// end of variables to set

function Upload() {
	var rValue="";
	var sOptions = "status=no, resizable= no, scrollbars= no, toolbar= no,location= no, menubar= no'";
	var sFormSize = "";
	if (navigator.appName == "Microsoft Internet Explorer" && btestNonIE != true) { //btestNonIE is just for testing
		//IE Browser
		sOptions = "status:no; unadorned:yes; scroll:no; help:no; resizable:no; toolbar:no";
		var sRequests = "?folder=" + sUploadFolder;
		sRequests += "&archive=" + sArchiveFolder;
		sRequests += "&overwrite=" + sOverwritePrompt;
		rValue = showModalDialog('FileUploader.aspx' + sRequests + '','FileUploader','dialogHeight:220px; dialogWidth:650px;' + sOptions + '');
		if (rValue != undefined) {
		    update_field(rValue,sReturnForm,sReturnField);
		}
	}else{
		//Not IE Browser
		var sRequests = "?folder=" + sUploadFolder;
		sRequests += "&archive=" + sArchiveFolder;
		sRequests += "&retForm=" + sReturnForm;
		sRequests += "&retField=" + sReturnField;
		sRequests += "&overwrite=" + sOverwritePrompt;
		window.open('FileUploader.aspx' + sRequests + '','FileUploader','height=220, width=650," + sOptions + "');
	}
}

function update_field(sNewValue,sForm,sField)
{
	eval("document." + sForm + "[sField].value = sNewValue;");
	//__doPostBack('btnSubmit','');  //auto postback so filename is saved
}

</script>

<form id="edit_Content" name="edit_Content" method="post" >
<input type=text  name="FileName" size="60" maxlength="" value="" >
&nbsp;
<input class=cmd type=button onClick="javascript:Upload();" value='UPLOAD'>
</form>

</BODY>
</HTML>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
Started programming in Business Basic in the 1980's and acquired my AS in Computer Science at that time. Promoted to IS Manager after one year of programming (sink or swim).
Self taught in SMC Basic, Visual Basic, C Shell, perl, ASP, JavaScript, vb.net, asp.net.
Now working as a Network Administrator at a hospital in Northern California.
Fell into a webmaster role when implementing the company's intranet website to support documentation.

Comments and Discussions