hey
I have a form for sending and assigning news to people .. and by that they
can attach their file and then choose one item from our list as category
or manager list and then click on submit and it will be send as well.. but
my prblem is when the user browse the file it just keeps the path of the
file on the textbox and then user see the selected item which can add or
remove them as well.. when he dose that I mean the second part, the file
which has selected on that textbox will be gone by itself... and user
should attach the file again.. so do u know any way to keep the path file
in the form although we have some other transaction ... add button /remove
button (post back)...
I sent you the part of sending email which is working by submit button
only... I hope you can help me ...
please help me ...
thank you so much
here is the sending mail code:
private void btnSubmit_Click(object sender, System.EventArgs e)
{
//some string manipulations to extract the
filename from the full file path
//save the file to the destination path on your
server
try
{
ManagersDB Managers = new ManagersDB();
string sOldName="";
string sNewName="";
if(inpFile.PostedFile.FileName!="")
{
//getting file names
string nam =
inpFile.PostedFile.FileName ;
int i= nam.LastIndexOf("\\") ;
sOldName =nam.Substring(i);
i=sOldName.LastIndexOf(".");
String sExt = "";
if (i>0) { sExt =
sOldName.Substring(i); }
sNewName= Guid.NewGuid().ToString()
+sExt;
//POST THE FILE
inpFile.PostedFile.SaveAs
("c:\\mgrNewsFiles\\"+sNewName); //for files
inpFile.PostedFile.SaveAs
("c:\\mgrNewsFiles\\"+sOldName); //for distribution/delete
}
//DO THE DB STUFF
//Insert Doc Data --> ManagerDocs, Insert
Mapping Data --> FirmDocMapping
int[] iFirmIDs = new int
[lstAssigned.Items.Count/*+1*/];
int iCnt=0;
foreach(ListItem li in lstAssigned.Items)
{
iFirmIDs[iCnt] = Convert.ToInt16
(li.Value);
iCnt++;
}
/*//add all
iFirmIDs[iCnt] = -1;
//adding "all firms" folks*/
Managers.SetManagerDocInfo(txtTitle.Text,
sNewName, sOldName, Convert.ToDateTime(txtDate.Text), Convert.ToInt16
(selCategories.SelectedItem.Value),Convert.ToInt16
(selPosters.SelectedItem.Value),txtAbstract.Text,iFirmIDs);
//Send the mail
MailMessage oMsg = new MailMessage();
oMsg.Bcc = FormatMessageToList(iFirmIDs);
oMsg.From = "Manager.News@D...";
oMsg.Subject = txtTitle.Text;
oMsg.BodyFormat = MailFormat.Html;
oMsg.Body = "html page";
if(inpFile.PostedFile.FileName!="")
{
oMsg.Attachments.Add(new
MailAttachment("c:\\mgrNewsFiles\\"+sOldName));
}
SmtpMail.SmtpServer
= "smtp.domainname.com";
SmtpMail.Send(oMsg);
if(inpFile.PostedFile.FileName!="")
{
try
{
//delete file used for send
System.IO.File.Delete
("c:\\mgrNewsFiles\\"+sOldName);
}
catch (Exception oFileEx)
{
//exception if delete fails
throw oFileEx;
}
}
Response.Redirect("UploadConfirm.aspx");
}
catch(Exception E)
{
throw E;
}
}