November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
Ok, I found out how:
EPiServer.Web.Hosting.UnifiedFile uf = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(attachment) as EPiServer.Web.Hosting.UnifiedFile;
But the name of the attachmnet isn't the display name, is there anyway to change the name of the attachment in the mail.
Hi
I'm not sure if this is what you are asking, but can't you do something like this:
UnifiedFile file = HostingEnvironment.VirtualPathProvider.GetFile(filePath) as UnifiedFile;
if (file != null)
{
using(Stream stream = file.Open())
{
string fileName = "My_file_name";
Attachment attachment = new Attachment(stream, fileName, "application/pdf"); //Or other Mime-type
//Send mail
}
}
Thanx for the tip it made me find the .Name attribute on the attachment and instead of using a strem a solved it like this:
//On page:
// -------- START Building attachment string
string attachmentFiles = "";
foreach (ListItem li in CheckBoxListFiles.Items)
{
if (li.Selected == true)
{
attachmentFiles += li.Value + ";";
}
}
if (attachmentFiles.Contains(";"))
{
attachmentFiles = attachmentFiles.Substring(0, attachmentFiles.Length - 1);
}
string virtualFolder = FileDataSource.Root;
string attachments = "";
if (attachmentFiles.Length > 0)
{
foreach (string file in attachmentFiles.Split(';'))
{
string virtualFile = virtualFolder + file;
EPiServer.Web.Hosting.UnifiedFile uf = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(virtualFile) as EPiServer.Web.Hosting.UnifiedFile;
attachments += uf.LocalPath + "," + file + ";";
}
if (attachments.Contains(";"))
{
attachments = attachments.Substring(0, attachments.Length - 1);
}
}
// -------- END Finished Building attachment string
// Pass the attachments string to send mail function
//In the send mail function
if (attachments.Length != 0)
{
foreach (string attach in attachments.Split(';'))
{
string[] file = attach.Split(',');
Attachment attachment = new Attachment(file[0]);
attachment.Name = file[1];
msg.Attachments.Add(attachment);
}
}
I have a page where I can send a mail to specific users and has added a FileSystemDataSource to list files so I can attach them to the mail.
But to add them to the mail I need the relative path.
How do I get the relative path to an EPiServer Virtual Directory (ie Documents)?