-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: Girdhar77
Message 3 in Discussion
Hi Mamatha,
have a look at the below code.
private string strBaseLocation = "D:\\Temp\\Attachment\\";
private string strFolder;//added by rishi on 22/Mar/2004
private void Page_Load(object sender, System.EventArgs e)
{
if( Session["UserID"]== null)
{
Response.Redirect("../frmSessionErr.aspx");
}
else
{
// Put user code to initialize the page here
try
{
if(!Page.IsPostBack)
{
cmdDone.Enabled = false;
Session.Remove("dtbAttachedFiles");
BuildAndBindDataGrid();
lblAttachedFiles.Text =
getDateTime();
}
txtErrorMessage.Value = "";
}
catch(Exception ex)
{
throw ex;
}
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web
Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.cmdAttach.Click += new
System.EventHandler(this.cmdAttach_Click);
this.dbgAttachedFiles.DeleteCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.dbgAttachedFiles_
DeleteCommand);
this.cmdDone.Click += new
System.EventHandler(this.cmdDone_Click);
this.Load += new
System.EventHandler(this.Page_Load);
}
#endregion
//Function returns the date and time
private string getDateTime()
{
string datetime =
System.DateTime.Now.ToShortDateString().Replace("/","-")+"-"+
System.DateTime.Now.Hour+"-"+System.DateTime.Now.Minute;
return datetime;
}
private void BuildAndBindDataGrid()
{
DataTable dtAttachedFiles;
DataColumn dcFileName;
DataColumn dcSize;
try
{
dtAttachedFiles = new
DataTable("dtbAttachedFiles");
dcFileName = new DataColumn("AttachedFile",
typeof(string));
dcSize = new DataColumn("Size",
typeof(long));
dtAttachedFiles.Columns.Add(dcFileName);
dtAttachedFiles.Columns.Add(dcSize);
dbgAttachedFiles.DataSource =
dtAttachedFiles.DefaultView;
dbgAttachedFiles.DataKeyField =
"AttachedFile";
dbgAttachedFiles.DataBind();
Session["dtbAttachedFiles"] =
dtAttachedFiles;
}
catch(Exception ex)
{
throw ex;
}
}
private void cmdAttach_Click(object sender, System.EventArgs
e)
{
string strFileNameOnServer;
string strFileNameOnClient;
string strFullPathOnClient;
DataTable dtAttachedFiles;
DataRow drAttachedFiles;
string allAttachedFiles;
try
{
if(filUpload.PostedFile.ContentLength==0)
{
txtErrorMessage.Value="Cannot add
Invalid / Empty files ";
return;
}
if(filUpload.PostedFile.FileName != "")
{
// Full name on the client machine
including path
strFullPathOnClient =
filUpload.PostedFile.FileName;
// Only Path
strFileNameOnClient =
strFullPathOnClient.Substring(strFullPathOnClient.LastIndexOf("\\")+1);
/*
// Check for filename
if(File.Exists(strBaseLocation +
strFileNameOnClient))
{
txtErrorMessage.Value = "A
file with the specified name already exists on the server. Please choose a
different name.";
return;
}
*///Commented on 22/Mar/2004
//rishi start on 22/Mar/2004
//Creating a folder for every
problem logged.
//Check for Role
if (Session["ROLE"].ToString()=="SS"
|| Session["ROLE"].ToString()=="PE" )
{
strFolder =
Session["strCOID"].ToString()+"-"+getDateTime();
Directory.CreateDirectory(strBaseLocation+"\\"+strFolder);
}
else
{
strFolder =
Session["COMPANY"].ToString()+"-"+getDateTime();
Directory.CreateDirectory(strBaseLocation+"\\"+strFolder);
}
//rishi end
strFileNameOnServer =
strFileNameOnClient;
// save the file
filUpload.PostedFile.SaveAs(strBaseLocation+strFolder+"\\"+strFileNameOnServ
er );
// for grid
dtAttachedFiles =
(DataTable)Session["dtbAttachedFiles"];
drAttachedFiles =
dtAttachedFiles.NewRow();
//drAttachedFiles["AttachedFile"] =
strFileNameOnServer; //Commented on 22/Mar/04
drAttachedFiles["AttachedFile"] =
strFolder+"\\"+strFileNameOnServer;//Added on 22/Mar/04
drAttachedFiles["Size"] =
filUpload.PostedFile.ContentLength;
dtAttachedFiles.Rows.Add(drAttachedFiles);
Session["dtbAttachedFiles"] =
dtAttachedFiles;
dbgAttachedFiles.DataSource =
dtAttachedFiles.DefaultView;
dbgAttachedFiles.DataBind();
// enable done Button
if(cmdDone.Enabled == false)
{
cmdDone.Enabled = true;
}
// for label
allAttachedFiles =
(string)Session["allAttachedFiles"];
if(((allAttachedFiles == null) ||
(allAttachedFiles == "")))
{
allAttachedFiles =
strFolder+"\\"+strFileNameOnClient;
}
else
{
allAttachedFiles =
allAttachedFiles + ";" + strFolder+"\\"+strFileNameOnClient;
}
Session["allAttachedFiles"] =
allAttachedFiles;
lblAttachedFiles.Text =
allAttachedFiles;
}
else
{
// user has not selected any file
txtErrorMessage.Value = "Please
select a file first and then hit attach";
}
}
catch(Exception ex)
{
throw ex;
}
}
private void dbgAttachedFiles_DeleteCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataTable dtAttachedFiles;
string allAttachedFiles;
try
{
// for grid
dtAttachedFiles =
(DataTable)Session["dtbAttachedFiles"];
string key =
dbgAttachedFiles.DataKeys[e.Item.ItemIndex].ToString();
dtAttachedFiles.Select("AttachedFile='" +
key + "'")[0].Delete();
Session["dtbAttachedFiles"] =
dtAttachedFiles;
dbgAttachedFiles.DataSource =
dtAttachedFiles.DefaultView;
dbgAttachedFiles.DataKeyField =
"AttachedFile";
dbgAttachedFiles.DataBind();
// for label
allAttachedFiles=
(string)Session["allAttachedFiles"];
if(allAttachedFiles.Length == key.Length)
{
allAttachedFiles = "";
Session["allAttachedFiles"] =
allAttachedFiles;
lblAttachedFiles.Text =
allAttachedFiles;
File.Delete(strBaseLocation + key);
cmdDone.Enabled = false;
return;
}
if (allAttachedFiles.Split(new char[]{';'},
30).Length == 1)
{
allAttachedFiles.Remove(allAttachedFiles.IndexOf(";"), 1);
}
else
{
if(allAttachedFiles.LastIndexOf(key)
== (allAttachedFiles.Length- key.Length))
{
allAttachedFiles =
allAttachedFiles.Remove(allAttachedFiles.IndexOf(key)-1, key.Length+1);
}
else
{
allAttachedFiles =
allAttachedFiles.Remove(allAttachedFiles.IndexOf(key), key.Length+1);
}
}
Session["allAttachedFiles"] =
allAttachedFiles;
lblAttachedFiles.Text = allAttachedFiles;
File.Delete(strBaseLocation + key);
}
catch(Exception ex)
{
throw ex;
}
}
private void cmdDone_Click(object sender, System.EventArgs
e)
{
//DataSet dsAttachment=new DataSet();
//dsAttachment=(DataSet)Session["allAttachedFiles"];
string sTemp=(string)Session["allAttachedFiles"];
//string
sAttachment=dsAttachment.Tables[0].Rows[0].ToString();
// Add code to redirect from the Page here.
// User (string)Session["allAttachedFiles"] to
access attached Files
try
{
//Page.RegisterClientScriptBlock("CloseScr",
"<script
language=\"javascript\">\nwindow.parent.refresh();\nwindow.close();\n</scrip
t>");
Page.RegisterClientScriptBlock("CloseScr",
"<script language=\"javascript\">\nwindow.close();\n</script>");
}
catch(Exception ex)
{
throw ex;
}
}
}
}
-----Original Message-----
From: Mamatha_md [mailto:[EMAIL PROTECTED]
Sent: Friday, March 19, 2004 11:39 AM
To: BDOTNET
Subject: Multiple file uploads
-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: Mamatha_md
Message 1 in Discussion
Hi all, How to achieve uploading multiple files using a single file browse
button? Thanks, Mamatha
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your
E-mail Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On
the pre-addressed e-mail message that opens, simply click "Send". Your
e-mail address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]
*********************************************************************
Disclaimer: The information in this e-mail and any attachments is
confidential / privileged. It is intended solely for the addressee or
addressees. If you are not the addressee indicated in this message, you may
not copy or deliver this message to anyone. In such case, you should destroy
this message and kindly notify the sender by reply email. Please advise
immediately if you or your employer does not consent to Internet email for
messages of this kind.
*********************************************************************
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]