Link to home
Create AccountLog in
Avatar of webdork
webdork

asked on

Classic ASP conversion to .NET

I'm in the middle of converting over a Classic ASP routine to .NET. I understand the ASP pretty good, the .NET not too good yet.

I need to pass a session variable from the ASP to the .NET. I've figured out a way by posting a form variable from ASP to .NET.  It looks like session variables don't travel between the platforms.

Once in the .NET, I need to build a folder with the same name as the passed in session var. Then, after the .NET work (file uploads) is complete, I need to redirect to a different ASP page carrying the session var.

Any help and ideas appreciated.


CODE BEHIND

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

public class WebForm1 : System.Web.UI.Page {
	protected ComponentArt.Web.UI.Upload Upload1;
	protected Label lblFeedback;

  private bool IsOnWebSite()
  {
    return Request.Url.ToString().ToLower().Contains(".componentart.com");
  }

  private void Page_Load(object sender, System.EventArgs e)
  {
    Upload1.TempFileFolder = Server.MapPath("~/common/uploads/temp");
  }

  private void Upload1_OnUploaded(object sender, ComponentArt.Web.UI.UploadUploadedEventArgs args)
  {
    foreach (ComponentArt.Web.UI.UploadedFileInfo oInfo in args.UploadedFiles)
    {
      lblFeedback.Text += "Uploaded file: " + oInfo.FileName + ", size " + oInfo.Size + " bytes<br/>\n";

      if (!IsOnWebSite())
      {
        oInfo.SaveAs(Path.Combine(Server.MapPath("~/common/uploads"), oInfo.FileName));
      }
    }
  }

	#region Web Form Designer generated code
	override protected void OnInit(EventArgs e) {
		InitializeComponent();
		base.OnInit(e);
	}
	private void InitializeComponent() {
		this.Load += new System.EventHandler(this.Page_Load);
		Upload1.Uploaded += new ComponentArt.Web.UI.Upload.UploadedEventHandler(Upload1_OnUploaded);
	}
	#endregion
}




WebFORM

<%@ Page Language="C#" Src="WebForm3.aspx.cs" AutoEventWireup="false" Inherits="WebForm1" %>
<%@ Register TagPrefix="Demos" TagName="Css" Src="~/common/ascx/css.ascx"%>
<%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head runat="server">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

	<title>TRGS Upload Routine</title>
	<Demos:Css RunAt="server" Id="DemoCss" />

	<link href="style.css" type="text/css" rel="stylesheet" />

<script type="text/javascript">
function file_change(sender,args) { check_upload_queue(sender); }

function check_upload_queue(ctrl) {
	var btn = document.getElementById("btn-upload");
	if (ctrl.GetFiles().length > 0) btn.className = "upload";
	else btn.className = "upload-d";
}

function add_file(ctrl,el) {
	ctrl.AddFile();
	if (ctrl.FileCount == ctrl.MaximumFileCount) el.className = "add-d";
}

function remove_file(ctrl,item) {
	if (ctrl.FileCount > 1) ctrl.RemoveFileAt(item);
	//else { ctrl.ClearFiles();ctrl.AddFile(); }
	//else ctrl.ClearFiles();
	//ctrl.ClearFiles();

	if (ctrl.FileCount < ctrl.MaximumFileCount) document.getElementById("btn-add").className = "add";
}


function upload_begin(sender,args) {
	//UploadDialog.Show();
}


function upload_end(sender,args) {
//alert('upload done')
}

function generate_file_list(ctrl,cur) {
	var files = ctrl.GetFiles();
	var out = "";
	var cls = "done";

	for (var f in files) {
		var file = files[f].substring(files[f].lastIndexOf("\\") + 1,files[f].length);
		var li = "<li class=\"" + cls + "\">";
		if (file == cur) {
			li = (ctrl.Uploading) ? "<li class=\"cur\">" 	: "<li class=\"done\">";
			cls = "";
		}
		out += li + file + "</li>";
	}

	return "<ul>" + out + "</ul>";
}

//	File size functions
function format_file_size(n,fmt) {
	if (!fmt) {		//	no formatting specified; automatically select the best format
		if (n < 1000) fmt = "b";
		else if (n < 1000000) fmt = "kb";
		else if (n < 1000000000) fmt = "mb";
		else fmt = "gb";
	}

	switch(fmt.toLowerCase()) {
		case "kb": return String((n * 0.001).toFixed(2)) + " KB";break;
		case "mb": return String((n * 0.000001).toFixed(2)) + " MB";break;
		case "gb": return String((n * 0.000000001).toFixed(2)) + " GB";break;
		default: return String(n.toFixed(2)) + " B";
	}
}

function get_percentage(n) { return String(Math.round(n * 100)); }

//	Time functions
function format_time(t,txt) {
	var s = Math.floor(t);
	var m = Math.floor(s / 60);
	var h = Math.floor(m / 60);

	if (!txt) {
		//	Output will always have be least mm:ss
		s = pad_time(s % 60);
		m = pad_time(m % 60) + ":";
		h = (h == 0) ? "" : pad_time(h % 60) + ":";

		return (h + m + s);
	} else {
		var secs = (s > 1) ? "seconds" : "second";			//	plural & singular second units
		var mins = (m > 1) ? "minute" : "minute";			//	plural & singular minute units
		var hours = (h > 1) ? "hours" : "hour";				//	plural & singular hour units

		s = (s > 0) ? String(s) + " " + secs : "";			//	string or empty?
		m = (m > 0) ? String(m) + " " +  mins : "";			//	string or empty?
		h = (h > 0) ? String(h) + " " + hours : "";			//	string or empty?

		var out = "";
		if (h !== "") {										//	longer than an hour
			out = h;
			if (m != "") out += ", " + m;					//	at least one minute
			if (s != "") out += ", " + s;					//	at least one second
		}

		if (m !== "" && out == "") {						//	shorter than an hour, greater than 60 seconds
			out += m;
			if (s != "") out += ", " + s;					//	at least one second
		}

		if (s !== "" && out == "") out = s;					//	at least one second

		if (out == "") out = "less than 1 second";			//	less than a second

		return out;
	}
}

function pad_time(t) { return String(((t > 9) ? "" : "0") + t); }

function get_file_position(ctrl,cur) {
	var files = ctrl.GetFiles();
	for (var i = 0; i < files.length; i++) {
		var file = files[i].substring(files[i].lastIndexOf("\\") + 1,files[i].length);
		if (file == cur) return String(i + 1);
	}

	return "1";
}

function init_upload(ctrl) {
	ctrl.Upload();
	UploadDialog.Show();
}

(new Image()).src = "images/vertical.png";

</script>
</head>
<body>
<form id="Form1" method="post" runat="server">


	<div class="DemoArea">

		<div style="width:300px;height:300px;background-image:url('images/vertical.png') repeat-y;display:none;visibility:hidden;"></div>

		<div class="sel">
			<ComponentArt:Upload
				ID="Upload1"
				RunAt="server"
				MaximumFileCount="6"
				AutoPostBack="false"
				FileInputClientTemplateId="FileInputTemplate"
				UploadCompleteClientTemplateId="CompletedTemplate"
				FileInputImageUrl="images/_browse.png"
				FileInputHoverImageUrl="images/_browse-h.png"
				ProgressClientTemplateId="ProgressTemplate"
				ProgressDomElementId="upload-progress"
			 OverwriteExistingFiles="True">
				<ClientEvents>
					<FileChange EventHandler="file_change" />
					<UploadBegin EventHandler="upload_begin" />
					<UploadEnd EventHandler="upload_end" />
				</ClientEvents>

				<ClientTemplates>
					<ComponentArt:ClientTemplate ID="FileInputTemplate">
						<div class="file">
							<div class="## DataItem.FileName ? "filename" : "filename empty"; ##"><input value="## DataItem.FileName ? DataItem.FileName : "Please select a file to upload"; ##" onfocus="this.blur();" /></div>
							<a href="javascript:void(0);" onclick="this.blur();return false;" class="browse" title="Browse for a file">#$FileInputImage</a>
							<a href="javascript:void(0);" onclick="remove_file(## Parent.Id ##,## DataItem.FileIndex ##);return false;" class="remove" title="Remove this file"></a>
						</div>
					</ComponentArt:ClientTemplate>

					<ComponentArt:ClientTemplate ID="ProgressTemplate">
						<!-- Dialogue contents -->
						<div class="con">
							<div class="stat">
								<h3 rel="total">Total Progress:</h3>
								<div class="prog">
									<div class="con">
										<div class="bar" style="width:## get_percentage(DataItem.Progress) ##%;"></div>
									</div>
								</div>
								<div class="lbl" style="text-align:right;"><strong>## format_file_size(DataItem.ReceivedBytes) ##</strong> of <strong>## format_file_size(DataItem.TotalBytes) ##</strong> (## get_percentage(DataItem.Progress) ##%) Uploaded</div>
							</div>

							<div class="list">
								<h3>Uploading files <span style="font-size:11px;">(<strong>## get_file_position(Parent,DataItem.CurrentFile) ##</strong> of <strong>## Parent.GetFiles().length ##</strong>):</span></h3>
								<div class="files">## generate_file_list(Parent,DataItem.CurrentFile); ##</div>
							</div>
						</div>
						<!-- /Dialogue contents -->

						<!-- Dialogue footer -->
						<div class="ftr">
							<div class="ftr-l"></div>
							<div class="ftr-m">
								<div class="info">
									<span>Elapsed time: <strong>## format_time(DataItem.ElapsedTime); ##</strong></span>
									<span style="padding-left:8px;">Estimated time: <strong>## format_time(DataItem.ElapsedTime + DataItem.RemainingTime); ##</strong></span>
									<span style="padding-left:8px;">Speed: <strong>## DataItem.Speed.toFixed(2) ## KB/S</strong></span>
								</div>
								<div class="btns">
									<a onclick="Parent.abort();return false;" href="javascript:void(0);" rel="cancel">
										<span class="l"></span>
										<span class="m" id="btn1">Cancel Upload</span>
										<span class="r"></span>
									</a>
								</div>
							</div>
							<div class="ftr-r"></div>
						</div>
						<!-- /Dialogue footer -->
					</ComponentArt:ClientTemplate>

					<ComponentArt:ClientTemplate ID="CompletedTemplate">
						<!-- Dialogue contents -->
						<div class="con">
							<div class="stat">
								<h3 style="text-align:center;" class="red">&mdash; Upload Complete &mdash;</h3>
								<div class="prog">
									<div class="con">
										<div class="bar" style="width:## get_percentage(DataItem.Progress) ##%;"></div>
									</div>
								</div>
								<div class="lbl" style="text-align:right;"><strong>## format_file_size(DataItem.ReceivedBytes) ##</strong> of <strong>## format_file_size(DataItem.TotalBytes) ##</strong> (## get_percentage(DataItem.Progress) ##%) Uploaded</div>
							</div>

							<div class="list">
								<h3><strong>## Parent.GetFiles().length ##</strong> ## (Parent.GetFiles().length > 1) ? "files" : "file" ## uploaded in <strong>## format_time(DataItem.ElapsedTime,true); ##</strong>:</h3>
								<div class="files">## generate_file_list(Parent,DataItem.CurrentFile); ##</div>
							</div>
						</div>
						<!-- /Dialogue contents -->

						<!-- Dialogue footer -->
						<div class="ftr">
							<div class="ftr-l"></div>
							<div class="ftr-m">
								<div class="btns">
									<a onclick="UploadDialog.close();return false;" href="javascript:void(0);" rel="cancel">
										<span class="l"></span>
										<span class="m" style="padding-left:6px;padding-right:6px;">Close</span>
										<span class="r"></span>
									</a>
								</div>
							</div>
							<div class="ftr-r"></div>
						</div>
						<!-- /Dialogue footer -->
					</ComponentArt:ClientTemplate>
				</ClientTemplates>
			</ComponentArt:Upload>
		</div>
		<div class="actions" rel="Upload1">
			<a href="javascript:void(0);" onclick="add_file(Upload1,this);this.blur();return false;" class="add" id="btn-add"></a>
			<a href="javascript:void(0);" onclick="init_upload(Upload1);this.blur();return false;" class="upload-d" id="btn-upload"></a>
		</div>


		<%-- Upload Dialogue & Control --%>
		<ComponentArt:Dialog
			ID="UploadDialog"
			RunAt="server"
			AllowDrag="true"
			AllowResize="false"
			Modal="false"
			Alignment="MiddleCentre"
			Width="458"
			Height="247"
			ContentCssClass="dlg-up"
			ContentClientTemplateId="UploadContent"
		>
			<ClientTemplates>
				<ComponentArt:ClientTemplate id="UploadContent">
					<div class="ttl" onmousedown="UploadDialog.StartDrag(event);">
						<div class="ttlt">
							<div class="ttlt-l"></div>
							<div class="ttlt-m">
								<a class="close" href="javascript:void(0);" onclick="UploadDialog.close();return false;"></a>
								<span>Upload</span>
							</div>
							<div class="ttlt-r"></div>
						</div>

						<div class="ttlb">
							<div class="ttlb-l"></div>
							<div class="ttlb-m"></div>
							<div class="ttlb-r"></div>
						</div>
					</div>

					<!-- for contents & footer, see upload progress client template -->
					<div id="upload-progress"></div>
				</ComponentArt:ClientTemplate>
			</ClientTemplates>
		</ComponentArt:Dialog>

	    <br />
        <% Session["SID"] = Request["SID"];
           Response.Write("SessionID=" + Session["SID"]);
        
            %>

        </div>


</form>
</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Scubago
Scubago

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account