Click here to Skip to main content
12,506,209 members (53,047 online)
Click here to Skip to main content

Stats

35K views
840 downloads
42 bookmarked
Posted

ASP.NET File Uploader with Overwrite Message

, 3 Dec 2008 CPOL
Intranet file upload dialog box with overwrite prompt and file archiving.
archive
bin
FileUploader.dll
Images
ajaxloader.gif
blank.gif
btnBrowse.jpg
btnBrowseDisabled.JPG
btnCancel.jpg
btnCancelDisabled.jpg
btnCancelMouseOver.jpg
btnClose.jpg
btnCloseDisabled.jpg
btnCloseMouseOver.jpg
btnOverwrite.jpg
btnOverwriteDisabled.jpg
btnOverwriteMouseOver.jpg
btnReplace.jpg
btnReplaceDisabled.jpg
btnReplaceMouseOver.jpg
btnSave.jpg
btnSaveDisabled.jpg
btnSaveMouseOver.jpg
icon_caution.gif
My Project
Application.myapp
pending
FileUploader.vbproj.user
<!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)

Share

About the Author

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

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160927.1 | Last Updated 4 Dec 2008
Article Copyright 2008 by BrianLaF
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid