It difficult to explain without some background but here goes.
I am the owner of this website but not the original programmer. He gone and I have to pickup the pieces
This website has members that access a specific folder via ftp from the iphone and Ipad. What I am trying to accomplish is to take the merged file that is being created via the merge.cs and save it to that folder so that they may access it via FTP. Then once the file is created and if the member opts in I also want to email it as an attachment and send it via SMTP. But right now One thing at a time. I am not very experienced in programming in C# asp.net or any other language. So just call me a newbie. Any help would be appreciated. This is the rest of the page.
I have put bits and piece from other webpage that are currently working on the site but I am stuck on this tempfile issue.
private void SaveFile(string tempFile)
{
long userId = -1;
userId = Convert.ToInt64(Session["userId"]);
foreach (UploadedFile file in tempFile)
if (file.ContentLength < 20000000)
{
if (userId > 0)
{
UserDAO objUserDAO = new UserDAO();
User objUser = objUserDAO.GetUser(userId);
if (objUser != null)
strTargetFolder = "~/" + strDataDir + "/" + objUser.UserName;
string targetFolder = Server.MapPath(strTargetFolder);
string targetFileName = Path.Combine(targetFolder, file.GetName());
targetFileName = getFileName(strTargetFolder, targetFileName, targetFileName, 0);
if (!Directory.Exists(targetFolder))
{
Directory.CreateDirectory(targetFolder);
}
file.SaveAs(targetFileName);
}
}
}
protected void RadUpload1_FileExists(object sender, Telerik.Web.UI.Upload.UploadedFileEventArgs e)
{
int counter = 1;
UploadedFile file = e.UploadedFile;
string targetFolder = Server.MapPath(RadUpload1.TargetFolder);
string targetFileName = Path.Combine(targetFolder, file.GetNameWithoutExtension()) + counter.ToString() + file.GetExtension();
while (File.Exists(targetFileName))
{
counter++;
targetFileName = Path.Combine(targetFolder, file.GetNameWithoutExtension()) + counter.ToString() + file.GetExtension();
}
file.SaveAs(targetFileName);
}
protected string getFileName(string targetFolder, string originalFilePath, string filePath, int counter)
{
if (File.Exists(filePath))
{
counter++;
filePath = Server.MapPath(Path.Combine(targetFolder, Path.GetFileNameWithoutExtension(originalFilePath)) + counter.ToString() + Path.GetExtension(filePath));
filePath = getFileName(targetFolder, originalFilePath, filePath, counter);
}
return filePath;
}
private void SendEmail(string strFileName)
{
long userId = long.Parse(Session["UserID"].ToString());
UserDAO objUserDAO = new UserDAO();
User objUser = objUserDAO.GetUser(Convert.ToInt64(userId));
string strSendEmail = null;
if(objUser.ProflightEmail != null)
strSendEmail = objUser.ProflightEmail.Trim();
else
strSendEmail = objUser.Email.Trim();
string UsName = objUser.LastName;
MailMessage mailMessage = new MailMessage ();
mailMessage.From = new MailAddress("NoReply@Proflightlog.com");
mailMessage.To.Add(strSendEmail);
mailMessage.Subject = "ProFlightLog Charting Service -TPP Procedures Attached";
mailMessage.Body = FormatMessage1(UsName);
if (strFileName != null)
{
Attachment attach = new Attachment(Server.MapPath(strFileName));
mailMessage.Attachments.Add(attach);
string attach1 = strFileName;
}
}