Krishna44
asked on
Windows Control in ASP.NET web page
i am using .net 2003 and i have developed windows control library and i want to use it in web page developed in asp.net.
how can i do that??
i need detailed explanation.
please let me know. Its urgent.
thanks in advance.
how can i do that??
i need detailed explanation.
please let me know. Its urgent.
thanks in advance.
<HTML>
<HEAD>
<SCRIPT>
function load()
{
}
function fileUpload()
{
if (true == upload1.FilesPending)
{
upload1.UploadFiles();
}
}
function incrementWait()
{
window.status += ".";
}
</SCRIPT>
<SCRIPT FOR="upload1" EVENT="BeginUpload">
window.status = "uploading files...please wait";
</SCRIPT>
<SCRIPT FOR="upload1" EVENT="UploadComplete">
window.alert("Upload complete");
</SCRIPT>
</HEAD>
<BODY onload="load();">
<OBJECT id="upload1" classid="Upload.dll#TestCo rp.ClientC ontrols.Mu ltiUploadC trl" width=800 height=300 style="font-size:12;">
<PARAM Name="FileUploadURL" Value="http://localhost/ServerFileUpload/UploadFile.aspx">
<PARAM Name="MaxSessionUpload" Value="10646">
</OBJECT><p>
<button id="btnUpload" onclick="fileUpload();">
Upload Files
</button>
</BODY>
</HTML>
<HEAD>
<SCRIPT>
function load()
{
}
function fileUpload()
{
if (true == upload1.FilesPending)
{
upload1.UploadFiles();
}
}
function incrementWait()
{
window.status += ".";
}
</SCRIPT>
<SCRIPT FOR="upload1" EVENT="BeginUpload">
window.status = "uploading files...please wait";
</SCRIPT>
<SCRIPT FOR="upload1" EVENT="UploadComplete">
window.alert("Upload complete");
</SCRIPT>
</HEAD>
<BODY onload="load();">
<OBJECT id="upload1" classid="Upload.dll#TestCo
<PARAM Name="FileUploadURL" Value="http://localhost/ServerFileUpload/UploadFile.aspx">
<PARAM Name="MaxSessionUpload" Value="10646">
</OBJECT><p>
<button id="btnUpload" onclick="fileUpload();">
Upload Files
</button>
</BODY>
</HTML>
using System;
using System.Threading;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Net;
using System.Runtime.InteropServ ices;
using System.Security;
using System.Security.Permission s;
using System.IO;
namespace TestCorp.ClientControls
{
/// <summary>
/// Upload multiple files to a server-side web app using an
/// intuitive interface.
/// </summary>
[ClassInterface(ClassInter faceType.N one), ComSourceInterfaces(typeof (IMultiUpl oadCtrlCOM Events))]
public class MultiUploadCtrl : System.Windows.Forms.UserC ontrol, IMultiUploadCtrlCOMIncomin g
{
private System.Windows.Forms.Label lbl1;
private System.Windows.Forms.Butto n selectDir;
/// Required designer variable.
private System.ComponentModel.Cont ainer components = null;
// URL supplied by user.
private string uploadURL;
// The current upload size for all selected files.
private long totalUploadSize;
// The max upload size per session. -1 signifies
// unlimited upload.
private int maxUpload;
// The number of bytes already uploaded.
private long bytesUploaded;
// An event signaling the end of our current upload batch.
public delegate void UploadCompleteHandler();
public event UploadCompleteHandler UploadComplete;
public delegate void BeginUploadHandler();
public event BeginUploadHandler BeginUpload;
// Hashtable of selected files.
// We use this to cache information about the file that
// we only need to retrieve once, such as file size.
protected Hashtable fileTable;
// The thread we use to upload files to the
// web server.
protected Thread uploadThread;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label lblUploadByteAmount;
private System.Windows.Forms.Butto n btnRemove;
private System.Windows.Forms.Butto n btnUpload;
private System.Timers.Timer timer1;
private System.Windows.Forms.ListB ox fileListBox;
public MultiUploadCtrl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
totalUploadSize = 0;
maxUpload = -1;
bytesUploaded = 0;
fileTable = new Hashtable();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label ();
this.selectDir = new System.Windows.Forms.Butto n();
this.lbl1 = new System.Windows.Forms.Label ();
this.timer1 = new System.Timers.Timer();
this.btnRemove = new System.Windows.Forms.Butto n();
this.lblUploadByteAmount = new System.Windows.Forms.Label ();
this.btnUpload = new System.Windows.Forms.Butto n();
this.fileListBox = new System.Windows.Forms.ListB ox();
((System.ComponentModel.IS upportInit ialize)(th is.timer1) ).BeginIni t();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 192);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(152, 24);
this.label1.TabIndex = 4;
this.label1.Text = "Total Bytes to Upload:";
//
// selectDir
//
this.selectDir.Location = new System.Drawing.Point(312, 48);
this.selectDir.Name = "selectDir";
this.selectDir.Size = new System.Drawing.Size(76, 21);
this.selectDir.TabIndex = 2;
this.selectDir.Text = "Browse...";
this.selectDir.Click += new System.EventHandler(this.s electDir_C lick);
//
// lbl1
//
this.lbl1.Location = new System.Drawing.Point(16, 16);
this.lbl1.Name = "lbl1";
this.lbl1.Size = new System.Drawing.Size(256, 32);
this.lbl1.TabIndex = 0;
this.lbl1.Text = "Files to Upload:";
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.SynchronizingO bject = this;
this.timer1.Elapsed += new System.Timers.ElapsedEvent Handler(th is.timer1_ Elapsed);
//
// btnRemove
//
this.btnRemove.Enabled = false;
this.btnRemove.Location = new System.Drawing.Point(312, 78);
this.btnRemove.Name = "btnRemove";
this.btnRemove.Size = new System.Drawing.Size(76, 21);
this.btnRemove.TabIndex = 2;
this.btnRemove.Text = "Remove";
this.btnRemove.Click += new System.EventHandler(this.b tnRemove_C lick);
//
// lblUploadByteAmount
//
this.lblUploadByteAmount.L ocation = new System.Drawing.Point(219, 192);
this.lblUploadByteAmount.N ame = "lblUploadByteAmount";
this.lblUploadByteAmount.S ize = new System.Drawing.Size(77, 24);
this.lblUploadByteAmount.T abIndex = 5;
//
// btnUpload
//
this.btnUpload.Enabled = false;
this.btnUpload.Location = new System.Drawing.Point(312, 160);
this.btnUpload.Name = "btnUpload";
this.btnUpload.Size = new System.Drawing.Size(76, 21);
this.btnUpload.TabIndex = 2;
this.btnUpload.Text = "Upload";
this.btnUpload.Click += new System.EventHandler(this.b tnUpload_C lick);
//
// fileListBox
//
this.fileListBox.Location = new System.Drawing.Point(16, 48);
this.fileListBox.Name = "fileListBox";
this.fileListBox.Selection Mode = System.Windows.Forms.Selec tionMode.M ultiExtend ed;
this.fileListBox.Size = new System.Drawing.Size(280, 134);
this.fileListBox.TabIndex = 3;
//
// MultiUploadCtrl
//
this.BackColor = System.Drawing.Color.White ;
this.Controls.AddRange(new System.Windows.Forms.Contr ol[] {
this.btnUpload,
this.lblUploadByteAmount,
this.label1,
this.btnRemove,
this.fileListBox,
this.selectDir,
this.lbl1});
this.Name = "MultiUploadCtrl";
this.Size = new System.Drawing.Size(400, 264);
this.Load += new System.EventHandler(this.M ultiUpload Ctrl_Load) ;
((System.ComponentModel.IS upportInit ialize)(th is.timer1) ).EndInit( );
this.ResumeLayout(false);
}
#endregion
private void selectDir_Click(object sender, System.EventArgs e)
{
if (!IsValidUrl(uploadURL))
{
throw(new WebException("URL supplied is " + uploadURL + ". URLs for this control must start with either 'http' or 'https'."));
}
OpenFileDialog dirDialog = new OpenFileDialog();
dirDialog.Multiselect = true;
dirDialog.ShowDialog();
// Add to list.
new FileIOPermission(Permissio nState.Unr estricted) .Assert();
foreach (string fileListItem in dirDialog.FileNames)
{
// Has the user already selected this file?
// If so, don't add it again.
// !TODO - user notification of dupes?
if (!fileTable.Contains(fileL istItem))
{
AddFile(fileListItem);
}
}
CodeAccessPermission.Rever tAssert();
UpdateFileSizeDescription( );
}
/// <summary>
/// Upload all selected files to the server.
/// </summary>
/// <permission cref="">
/// Unrestricted FileIOPermission required for
/// access to entire disk and all shares.
/// </permission>
public void UploadFiles()
{
// Do not start the upload thread if one is
// already running.
if (null != uploadThread && uploadThread.IsAlive)
{
throw(new Exception("Cannot start a new upload - a previously requested upload is still executing."));
}
DoBeginUpload();
uploadThread = new Thread(new ThreadStart(UploadFilesThr ead));
uploadThread.Start();
}
/// <summary>
/// Worker thread that uploads all items to the
/// server script named by FileUploadUrl.
/// </summary>
/// <remarks>
/// Need to figure out how to throw multiple events
/// from a thread - the Timer technique is quite weak.
/// If this throws an error (and it does if we upload
/// in excess of 15MB of files), we'll never
/// see it.
/// </remarks>
protected void UploadFilesThread()
{
WebClient UploadObj = new WebClient();
object[] itemsCache = new object[fileListBox.Items.C ount];
// Error out if we're asked to upload files that don't exist.
if (0 == fileListBox.Items.Count)
{
// !TODO: Error mechanism needed.
throw(new Exception("You must browse for files before attempting an upload."));
}
// !TODO: Grant the ability to upload all files batch. WebClient doesn't support
// multiple files in the same upload txn, even though the standard
// does, so we'll roll our own classes later to handle this.
new FileIOPermission(Permissio nState.Unr estricted) .Assert();
fileListBox.Items.CopyTo(i temsCache, 0);
for (int i = 0; i < itemsCache.Length; i++)
{
// Trap any failures.
try
{
string item = (string)itemsCache[i]; // cast once
UploadObj.UploadFile(uploa dURL, item);
// Remove from the list individually, in case
RemoveFile(item);
UpdateFileSizeDescription( );
}
catch (WebException e)
{
throw(new WebException("Could not upload all of the files.", e));
}
}
CodeAccessPermission.Rever tAssert();
// We can't call a COM event from a thread other than the one on which the sinking
// occurred, or we'll generate an obscure exception. So set a timer in the main thread
// and force this event to occur elsewhere.
timer1.Interval = 1;
timer1.Start();
btnRemove.Enabled = false;
}
///<summary>
// Marks whether or not any files are waiting to be uploaded.
///</summary>
public bool FilesPending
{
get
{
return(fileListBox.Items.C ount > 0);
}
}
/// <summary>
/// The maximum number of files that can be uploaded in
/// this session, in bytes.
/// </summary>
public int MaxSessionUpload
{
get
{
if (-1 == maxUpload)
{
}
return(maxUpload);
}
set
{
if (maxUpload < 0)
{
maxUpload = -1;
}
else
{
maxUpload = Convert.ToInt32(value.ToSt ring());
}
}
}
/// <summary>
/// The number of bytes already uploaded.
/// </summary>
public int BytesUploaded
{
get
{
return((int)bytesUploaded) ;
}
}
public string FileUploadURL
{
get
{
return(uploadURL);
}
set
{
// IE suppresses any exceptions (IErrorInfo in COM parlance) thrown during
// IPersistPropertyBag:Load() . Check the integrity of this string later during
// control use instead of now.
if (null != value)
{
uploadURL = value.ToString();
}
}
}
private void MultiUploadCtrl_Load(objec t sender, System.EventArgs e)
{
fileListBox.SelectedIndexC hanged += new System.EventHandler(this.f ileListBox _SelectedI ndexChange d);
UpdateFileSizeDescription( );
}
private bool IsValidUrl(string url)
{
string urlTmp = url.ToLower();
// Note: covers both "http" and "https".
if (false == urlTmp.StartsWith("http"))
{
return false;
}
else
{
return true;
}
}
/// <summary>
/// Encapsulate all the updating required when a file
/// is added to the file list. For security reasons,
/// this method is never exposed via our public API.
/// </summary>
/// <param name="fileFullName">The file to add.</param>
protected void AddFile(string fileFullName)
{
CachedFileInfo cachedInfo;
FileInfo fInfo;
// Get file size from file system.
fInfo = new FileInfo(fileFullName);
cachedInfo.FileSizeBytes = fInfo.Length;
// Are we within our quota?
if (maxUpload > -1)
{
if (totalUploadSize + cachedInfo.FileSizeBytes > maxUpload)
{
throw(new Exception("The file " + fileFullName + "is " + cachedInfo.FileSizeBytes + " bytes. Adding this to your upload queue would violate your maximum quota for this upload session."));
}
}
fileListBox.Items.Add((obj ect)fileFu llName);
totalUploadSize += fInfo.Length;
fileTable.Add(fileFullName , cachedInfo);
btnUpload.Enabled = true;
}
/// <summary>
/// Encapsulate all the updating required when a file
/// is removed from the file list.
/// </summary>
/// <param name="fileFullName">The file to remove.</param>
protected void RemoveFile(string fileFullName)
{
fileListBox.Items.Remove(f ileFullNam e);
// Decrement size from file size total.
CachedFileInfo cfi = (CachedFileInfo)fileTable[ fileFullNa me];
totalUploadSize -= cfi.FileSizeBytes;
fileTable.Remove(fileFullN ame);
if (0 == fileListBox.Items.Count)
{
btnUpload.Enabled = false;
}
}
private void UpdateFileSizeDescription( )
{
lblUploadByteAmount.Text = Convert.ToString(totalUplo adSize/102 4) + "KB";
}
private void fileListBox_SelectedIndexC hanged(obj ect sender, System.EventArgs e)
{
if (0 == fileListBox.SelectedIndice s.Count)
{
btnRemove.Enabled = false;
}
else
{
btnRemove.Enabled = true;
}
}
private void btnRemove_Click(object sender, System.EventArgs e)
{
int SelectedCount = fileListBox.SelectedItems. Count;
object[] selItemsCache = new object[SelectedCount];
// use CopyTo() to prevent state problems w/ delete during foreach.
fileListBox.SelectedItems. CopyTo(sel ItemsCache , 0);
foreach (object o in selItemsCache)
{
RemoveFile((string)o);
}
UpdateFileSizeDescription( );
// The operation throws focus off the listbox, so
// disable the Remove button.
btnRemove.Enabled = false;
}
protected void DoBeginUpload()
{
if (BeginUpload != null)
{
// Assert ability to call unmanaged code.
new SecurityPermission(Securit yPermissio nFlag.Unma nagedCode) .Assert();
BeginUpload();
CodeAccessPermission.Rever tAssert();
}
}
protected void DoUploadComplete()
{
if (UploadComplete != null)
{
// Assert ability to call unmanaged code.
new SecurityPermission(Securit yPermissio nFlag.Unma nagedCode) .Assert();
UploadComplete();
CodeAccessPermission.Rever tAssert();
}
}
private void btnUpload_Click(object sender, System.EventArgs e)
{
UploadFiles();
}
// Fire the DoUploadComplete event after the secondary thread has finished its labors.
private void timer1_Elapsed(object sender, System.Timers.ElapsedEvent Args e)
{
timer1.Stop();
// Even necessary??
if (uploadThread.IsAlive)
{
uploadThread.Abort();
}
DoUploadComplete();
}
}
/// <summary>
/// Cache file information that might have been expensive to
/// retrieve, such as file size.
/// </summary>
internal struct CachedFileInfo
{
public long FileSizeBytes;
}
/// <summary>
/// Source interface for hooking up to COM events so that JScript/VBScript can sink event
/// handlers with us. Disgusting, but it works.
/// </summary>
[Guid("A59B958D-B363-454b- 88AA-BE862 6A131FB")]
[InterfaceType(ComInterfac eType.Inte rfaceIsIDi spatch)]
public interface IMultiUploadCtrlCOMEvents
{
[DispId(0x60020000)]
void UploadComplete();
[DispId(0x60020001)]
void BeginUpload();
}
/// <summary>
/// Default incoming interface for our control. Required when using COM-style events,
/// otherwise IE will no longer be able to access our public properties and methods.
/// </summary>
public interface IMultiUploadCtrlCOMIncomin g
{
void UploadFiles();
bool FilesPending {get;}
int MaxSessionUpload {get; set; }
int BytesUploaded {get;}
string FileUploadURL {get; set; }
}
}
using System.Threading;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Net;
using System.Runtime.InteropServ
using System.Security;
using System.Security.Permission
using System.IO;
namespace TestCorp.ClientControls
{
/// <summary>
/// Upload multiple files to a server-side web app using an
/// intuitive interface.
/// </summary>
[ClassInterface(ClassInter
public class MultiUploadCtrl : System.Windows.Forms.UserC
{
private System.Windows.Forms.Label
private System.Windows.Forms.Butto
/// Required designer variable.
private System.ComponentModel.Cont
// URL supplied by user.
private string uploadURL;
// The current upload size for all selected files.
private long totalUploadSize;
// The max upload size per session. -1 signifies
// unlimited upload.
private int maxUpload;
// The number of bytes already uploaded.
private long bytesUploaded;
// An event signaling the end of our current upload batch.
public delegate void UploadCompleteHandler();
public event UploadCompleteHandler UploadComplete;
public delegate void BeginUploadHandler();
public event BeginUploadHandler BeginUpload;
// Hashtable of selected files.
// We use this to cache information about the file that
// we only need to retrieve once, such as file size.
protected Hashtable fileTable;
// The thread we use to upload files to the
// web server.
protected Thread uploadThread;
private System.Windows.Forms.Label
private System.Windows.Forms.Label
private System.Windows.Forms.Butto
private System.Windows.Forms.Butto
private System.Timers.Timer timer1;
private System.Windows.Forms.ListB
public MultiUploadCtrl()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
totalUploadSize = 0;
maxUpload = -1;
bytesUploaded = 0;
fileTable = new Hashtable();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label
this.selectDir = new System.Windows.Forms.Butto
this.lbl1 = new System.Windows.Forms.Label
this.timer1 = new System.Timers.Timer();
this.btnRemove = new System.Windows.Forms.Butto
this.lblUploadByteAmount = new System.Windows.Forms.Label
this.btnUpload = new System.Windows.Forms.Butto
this.fileListBox = new System.Windows.Forms.ListB
((System.ComponentModel.IS
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 192);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(152, 24);
this.label1.TabIndex = 4;
this.label1.Text = "Total Bytes to Upload:";
//
// selectDir
//
this.selectDir.Location = new System.Drawing.Point(312, 48);
this.selectDir.Name = "selectDir";
this.selectDir.Size = new System.Drawing.Size(76, 21);
this.selectDir.TabIndex = 2;
this.selectDir.Text = "Browse...";
this.selectDir.Click += new System.EventHandler(this.s
//
// lbl1
//
this.lbl1.Location = new System.Drawing.Point(16, 16);
this.lbl1.Name = "lbl1";
this.lbl1.Size = new System.Drawing.Size(256, 32);
this.lbl1.TabIndex = 0;
this.lbl1.Text = "Files to Upload:";
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.SynchronizingO
this.timer1.Elapsed += new System.Timers.ElapsedEvent
//
// btnRemove
//
this.btnRemove.Enabled = false;
this.btnRemove.Location = new System.Drawing.Point(312, 78);
this.btnRemove.Name = "btnRemove";
this.btnRemove.Size = new System.Drawing.Size(76, 21);
this.btnRemove.TabIndex = 2;
this.btnRemove.Text = "Remove";
this.btnRemove.Click += new System.EventHandler(this.b
//
// lblUploadByteAmount
//
this.lblUploadByteAmount.L
this.lblUploadByteAmount.N
this.lblUploadByteAmount.S
this.lblUploadByteAmount.T
//
// btnUpload
//
this.btnUpload.Enabled = false;
this.btnUpload.Location = new System.Drawing.Point(312, 160);
this.btnUpload.Name = "btnUpload";
this.btnUpload.Size = new System.Drawing.Size(76, 21);
this.btnUpload.TabIndex = 2;
this.btnUpload.Text = "Upload";
this.btnUpload.Click += new System.EventHandler(this.b
//
// fileListBox
//
this.fileListBox.Location = new System.Drawing.Point(16, 48);
this.fileListBox.Name = "fileListBox";
this.fileListBox.Selection
this.fileListBox.Size = new System.Drawing.Size(280, 134);
this.fileListBox.TabIndex = 3;
//
// MultiUploadCtrl
//
this.BackColor = System.Drawing.Color.White
this.Controls.AddRange(new
this.btnUpload,
this.lblUploadByteAmount,
this.label1,
this.btnRemove,
this.fileListBox,
this.selectDir,
this.lbl1});
this.Name = "MultiUploadCtrl";
this.Size = new System.Drawing.Size(400, 264);
this.Load += new System.EventHandler(this.M
((System.ComponentModel.IS
this.ResumeLayout(false);
}
#endregion
private void selectDir_Click(object sender, System.EventArgs e)
{
if (!IsValidUrl(uploadURL))
{
throw(new WebException("URL supplied is " + uploadURL + ". URLs for this control must start with either 'http' or 'https'."));
}
OpenFileDialog dirDialog = new OpenFileDialog();
dirDialog.Multiselect = true;
dirDialog.ShowDialog();
// Add to list.
new FileIOPermission(Permissio
foreach (string fileListItem in dirDialog.FileNames)
{
// Has the user already selected this file?
// If so, don't add it again.
// !TODO - user notification of dupes?
if (!fileTable.Contains(fileL
{
AddFile(fileListItem);
}
}
CodeAccessPermission.Rever
UpdateFileSizeDescription(
}
/// <summary>
/// Upload all selected files to the server.
/// </summary>
/// <permission cref="">
/// Unrestricted FileIOPermission required for
/// access to entire disk and all shares.
/// </permission>
public void UploadFiles()
{
// Do not start the upload thread if one is
// already running.
if (null != uploadThread && uploadThread.IsAlive)
{
throw(new Exception("Cannot start a new upload - a previously requested upload is still executing."));
}
DoBeginUpload();
uploadThread = new Thread(new ThreadStart(UploadFilesThr
uploadThread.Start();
}
/// <summary>
/// Worker thread that uploads all items to the
/// server script named by FileUploadUrl.
/// </summary>
/// <remarks>
/// Need to figure out how to throw multiple events
/// from a thread - the Timer technique is quite weak.
/// If this throws an error (and it does if we upload
/// in excess of 15MB of files), we'll never
/// see it.
/// </remarks>
protected void UploadFilesThread()
{
WebClient UploadObj = new WebClient();
object[] itemsCache = new object[fileListBox.Items.C
// Error out if we're asked to upload files that don't exist.
if (0 == fileListBox.Items.Count)
{
// !TODO: Error mechanism needed.
throw(new Exception("You must browse for files before attempting an upload."));
}
// !TODO: Grant the ability to upload all files batch. WebClient doesn't support
// multiple files in the same upload txn, even though the standard
// does, so we'll roll our own classes later to handle this.
new FileIOPermission(Permissio
fileListBox.Items.CopyTo(i
for (int i = 0; i < itemsCache.Length; i++)
{
// Trap any failures.
try
{
string item = (string)itemsCache[i]; // cast once
UploadObj.UploadFile(uploa
// Remove from the list individually, in case
RemoveFile(item);
UpdateFileSizeDescription(
}
catch (WebException e)
{
throw(new WebException("Could not upload all of the files.", e));
}
}
CodeAccessPermission.Rever
// We can't call a COM event from a thread other than the one on which the sinking
// occurred, or we'll generate an obscure exception. So set a timer in the main thread
// and force this event to occur elsewhere.
timer1.Interval = 1;
timer1.Start();
btnRemove.Enabled = false;
}
///<summary>
// Marks whether or not any files are waiting to be uploaded.
///</summary>
public bool FilesPending
{
get
{
return(fileListBox.Items.C
}
}
/// <summary>
/// The maximum number of files that can be uploaded in
/// this session, in bytes.
/// </summary>
public int MaxSessionUpload
{
get
{
if (-1 == maxUpload)
{
}
return(maxUpload);
}
set
{
if (maxUpload < 0)
{
maxUpload = -1;
}
else
{
maxUpload = Convert.ToInt32(value.ToSt
}
}
}
/// <summary>
/// The number of bytes already uploaded.
/// </summary>
public int BytesUploaded
{
get
{
return((int)bytesUploaded)
}
}
public string FileUploadURL
{
get
{
return(uploadURL);
}
set
{
// IE suppresses any exceptions (IErrorInfo in COM parlance) thrown during
// IPersistPropertyBag:Load()
// control use instead of now.
if (null != value)
{
uploadURL = value.ToString();
}
}
}
private void MultiUploadCtrl_Load(objec
{
fileListBox.SelectedIndexC
UpdateFileSizeDescription(
}
private bool IsValidUrl(string url)
{
string urlTmp = url.ToLower();
// Note: covers both "http" and "https".
if (false == urlTmp.StartsWith("http"))
{
return false;
}
else
{
return true;
}
}
/// <summary>
/// Encapsulate all the updating required when a file
/// is added to the file list. For security reasons,
/// this method is never exposed via our public API.
/// </summary>
/// <param name="fileFullName">The file to add.</param>
protected void AddFile(string fileFullName)
{
CachedFileInfo cachedInfo;
FileInfo fInfo;
// Get file size from file system.
fInfo = new FileInfo(fileFullName);
cachedInfo.FileSizeBytes = fInfo.Length;
// Are we within our quota?
if (maxUpload > -1)
{
if (totalUploadSize + cachedInfo.FileSizeBytes > maxUpload)
{
throw(new Exception("The file " + fileFullName + "is " + cachedInfo.FileSizeBytes + " bytes. Adding this to your upload queue would violate your maximum quota for this upload session."));
}
}
fileListBox.Items.Add((obj
totalUploadSize += fInfo.Length;
fileTable.Add(fileFullName
btnUpload.Enabled = true;
}
/// <summary>
/// Encapsulate all the updating required when a file
/// is removed from the file list.
/// </summary>
/// <param name="fileFullName">The file to remove.</param>
protected void RemoveFile(string fileFullName)
{
fileListBox.Items.Remove(f
// Decrement size from file size total.
CachedFileInfo cfi = (CachedFileInfo)fileTable[
totalUploadSize -= cfi.FileSizeBytes;
fileTable.Remove(fileFullN
if (0 == fileListBox.Items.Count)
{
btnUpload.Enabled = false;
}
}
private void UpdateFileSizeDescription(
{
lblUploadByteAmount.Text = Convert.ToString(totalUplo
}
private void fileListBox_SelectedIndexC
{
if (0 == fileListBox.SelectedIndice
{
btnRemove.Enabled = false;
}
else
{
btnRemove.Enabled = true;
}
}
private void btnRemove_Click(object sender, System.EventArgs e)
{
int SelectedCount = fileListBox.SelectedItems.
object[] selItemsCache = new object[SelectedCount];
// use CopyTo() to prevent state problems w/ delete during foreach.
fileListBox.SelectedItems.
foreach (object o in selItemsCache)
{
RemoveFile((string)o);
}
UpdateFileSizeDescription(
// The operation throws focus off the listbox, so
// disable the Remove button.
btnRemove.Enabled = false;
}
protected void DoBeginUpload()
{
if (BeginUpload != null)
{
// Assert ability to call unmanaged code.
new SecurityPermission(Securit
BeginUpload();
CodeAccessPermission.Rever
}
}
protected void DoUploadComplete()
{
if (UploadComplete != null)
{
// Assert ability to call unmanaged code.
new SecurityPermission(Securit
UploadComplete();
CodeAccessPermission.Rever
}
}
private void btnUpload_Click(object sender, System.EventArgs e)
{
UploadFiles();
}
// Fire the DoUploadComplete event after the secondary thread has finished its labors.
private void timer1_Elapsed(object sender, System.Timers.ElapsedEvent
{
timer1.Stop();
// Even necessary??
if (uploadThread.IsAlive)
{
uploadThread.Abort();
}
DoUploadComplete();
}
}
/// <summary>
/// Cache file information that might have been expensive to
/// retrieve, such as file size.
/// </summary>
internal struct CachedFileInfo
{
public long FileSizeBytes;
}
/// <summary>
/// Source interface for hooking up to COM events so that JScript/VBScript can sink event
/// handlers with us. Disgusting, but it works.
/// </summary>
[Guid("A59B958D-B363-454b-
[InterfaceType(ComInterfac
public interface IMultiUploadCtrlCOMEvents
{
[DispId(0x60020000)]
void UploadComplete();
[DispId(0x60020001)]
void BeginUpload();
}
/// <summary>
/// Default incoming interface for our control. Required when using COM-style events,
/// otherwise IE will no longer be able to access our public properties and methods.
/// </summary>
public interface IMultiUploadCtrlCOMIncomin
{
void UploadFiles();
bool FilesPending {get;}
int MaxSessionUpload {get; set; }
int BytesUploaded {get;}
string FileUploadURL {get; set; }
}
}
you can problem with activate control and solution is over javascript
page:
<body >
<table style="margin-top:0px; padding-top:0px" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 100px;">
<select id="telefony" name="telefony">
</select>
</td>
<td style="width: 100px;">
<select id = "error_vypis" name = "error_vypis">
</select>
</td>
<td style="width: 200px;">
<script src="docwrite.js"></script >
</td>
<td style="width: 100px">
<input id="btnSubmit" name="btnSubmit" type="button" value="Call" onclick="CallNumber();" /></td>
<td style="width: 100px;">
<input id="btnSubmit1" name="btnSubmit1" type="button" value="Release" onclick="Release();" /></td>
</tr>
</table>
</body>
-------------------------- ---------- ------
docwrite.js:
document.write('<object id="CallUserControl1" classid="http:CallUserControl.dll#CallUserControl.CallUserControl" height="20" width="200" VIEWASTEXT></object>');
document.write('<SCRIPT FOR="CallUserControl1" EVENT="DoClick">setTimeout (CallUserC ontrol1.Fu nkce, 0);</SCRIPT>');
page:
<body >
<table style="margin-top:0px; padding-top:0px" cellpadding="0" cellspacing="0">
<tr>
<td style="width: 100px;">
<select id="telefony" name="telefony">
</select>
</td>
<td style="width: 100px;">
<select id = "error_vypis" name = "error_vypis">
</select>
</td>
<td style="width: 200px;">
<script src="docwrite.js"></script
</td>
<td style="width: 100px">
<input id="btnSubmit" name="btnSubmit" type="button" value="Call" onclick="CallNumber();" /></td>
<td style="width: 100px;">
<input id="btnSubmit1" name="btnSubmit1" type="button" value="Release" onclick="Release();" /></td>
</tr>
</table>
</body>
--------------------------
docwrite.js:
document.write('<object id="CallUserControl1" classid="http:CallUserControl.dll#CallUserControl.CallUserControl" height="20" width="200" VIEWASTEXT></object>');
document.write('<SCRIPT FOR="CallUserControl1" EVENT="DoClick">setTimeout
vilimed: Why are these posts in this thread ? I don't see any reference with this question !
Dhaest: This is real solution with Windows Control in HTML(ASP.NET) with solution events from Windows Control and with practicdal used without activated.
Is not true, what i am writing? it is problem?
Is not true, what i am writing? it is problem?
>> Dhaest: This is real solution with Windows Control in HTML(ASP.NET) with solution events from Windows Control and with practicdal used without activated
Ok, then I agree that you post it, but maybe next time you can tell it in the first post that you're going to post an example :)
Ok, then I agree that you post it, but maybe next time you can tell it in the first post that you're going to post an example :)
ASKER
hai every body,
i got it with simple control and i have done this in asp.net not in html.
i got it without additional dlls. but when im trying to use control with multiple dlls(means i am using third party dlls in my control) then its not working for me.
thanks for reply,
expecting solution
i got it with simple control and i have done this in asp.net not in html.
i got it without additional dlls. but when im trying to use control with multiple dlls(means i am using third party dlls in my control) then its not working for me.
thanks for reply,
expecting solution
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Forced accept.
Computer101
EE Admin
Computer101
EE Admin
Hosting a Windows Control in a Web Form
http://aspnet.4guysfromrolla.com/articles/052604-1.aspx