Asp.Net Upload Imagem cloudinary - asp.net

Good afternoon!
I have problems uploading images to a defined folder. As you can see, in my code I can upload to the cloudinary root, but not to a specific folder I created.
Cloudinary cloudinary = new Cloudinary(account);
string NomeImagem = "";
string TipoImagem = "";
string Versao = "";
byte[] binData = null;
string result = string.Empty;
if (Request.Files.Count > 0)
{
if (Request.Files["FotoURL"].ContentLength > 0)
{
using (BinaryReader b = new BinaryReader(Request.Files["FotoURL"].InputStream))
{
binData = b.ReadBytes(Request.Files["FotoURL"].ContentLength);
}
string teste = Convert.ToBase64String(binData);
byte[] imageBytes = Convert.FromBase64String(Convert.ToBase64String(binData));
using (MemoryStream ms = new MemoryStream(imageBytes))
{
DirectoryInfo dir = new DirectoryInfo(Server.MapPath("."));
string diretorio = dir.FullName.ToString();
try
{
var uploadParams = new ImageUploadParams()
{
File = new FileDescription(IdUsuario + "Perfiltemp.jpg", ms)
};
var uploadResult = cloudinary.Upload(uploadParams);
NomeImagem = uploadResult.JsonObj["public_id"].ToString();
TipoImagem = uploadResult.Format.ToString();
Versao = "v" + uploadResult.Version.ToString();
dados += "&FotoURL=http://res.cloudinary.com/diretor/aceleramei/image/upload/" + Versao + "/" + NomeImagem + "." + TipoImagem;
}
catch (Exception e)
{
string msg = e.ToString();
var uploadParams = new ImageUploadParams()
{
File = new FileDescription(#"" + Server.MapPath("~") + "\\Content\\layout\\img\\300x200.gif")
};
var uploadResult = cloudinary.Upload(uploadParams);
NomeImagem = uploadResult.JsonObj["public_id"].ToString();
TipoImagem = uploadResult.Format.ToString();
Versao = "v" + uploadResult.Version.ToString();
// dados += "&FotoURL=http://res.cloudinary.com/diretor/image/upload/" + Versao + "/" + NomeImagem + "." + TipoImagem;
}
}

Solução
string NomeImagem = "";
string TipoImagem = "";
string Versao = "";
// string Pasta = "teste";
byte[] binData = null;
string result = string.Empty;
if (Request.Files.Count > 0)
{
if (Request.Files["FotoURL"].ContentLength > 0)
{
using (BinaryReader b = new BinaryReader(Request.Files["FotoURL"].InputStream))
{
binData = b.ReadBytes(Request.Files["FotoURL"].ContentLength);
}
string teste = Convert.ToBase64String(binData);
byte[] imageBytes = Convert.FromBase64String(Convert.ToBase64String(binData));
using (MemoryStream ms = new MemoryStream(imageBytes))
{
DirectoryInfo dir = new DirectoryInfo(Server.MapPath("teste"));
string diretorio = dir.FullName.ToString();
try
{
var uploadParams = new ImageUploadParams()
{
File = new FileDescription(IdUsuario + "Perfiltemp.jpg" , ms),
PublicId = $"aceleramei/{System.IO.Path.GetFileName(IdUsuario)}",
EagerAsync = true
};
var uploadResult = cloudinary.Upload(uploadParams);
NomeImagem = uploadResult.JsonObj["public_id"].ToString();
TipoImagem = uploadResult.Format.ToString();
Versao = "v" + uploadResult.Version.ToString();
dados += "&FotoURL=http://res.cloudinary.com/diretor/image/upload/" + Versao + "/" + NomeImagem + "." + TipoImagem;
}
catch (Exception e)
{
string msg = e.ToString();
var uploadParams = new ImageUploadParams()
{
File = new FileDescription(#"" + Server.MapPath("~") + "\\Content\\layout\\img\\300x200.gif"),
PublicId = $"aceleramei/{System.IO.Path.GetFileName("")}",
EagerAsync = true
};
var uploadResult = cloudinary.Upload(uploadParams);
NomeImagem = uploadResult.JsonObj["public_id"].ToString();
TipoImagem = uploadResult.Format.ToString();
Versao = "v" + uploadResult.Version.ToString();
// dados += "&FotoURL=http://res.cloudinary.com/diretor/image/upload/" + Versao + "/" + NomeImagem + "." + TipoImagem;
}
}
}
else
{
var uploadParams = new ImageUploadParams()
{
File = new FileDescription(#"" + Server.MapPath("~") + "\\Content\\layout\\img\\300x200.gif"),
PublicId = $"aceleramei/{System.IO.Path.GetFileName("")}",
EagerAsync = true
};
var uploadResult = cloudinary.Upload(uploadParams);
NomeImagem = uploadResult.JsonObj["public_id"].ToString();
TipoImagem = uploadResult.Format.ToString();
Versao = uploadResult.Version.ToString();
dados += "&FotoURL=";
}
}
else
{
var uploadParams = new ImageUploadParams()
{
File = new FileDescription(#"" + Server.MapPath("~") + "\\Content\\layout\\img\\300x200.gif"),
PublicId = $"aceleramei/{System.IO.Path.GetFileName("")}",
EagerAsync = true
};
var uploadResult = cloudinary.Upload(uploadParams);
NomeImagem = uploadResult.JsonObj["public_id"].ToString();
TipoImagem = uploadResult.Format.ToString();
Versao = "v" + uploadResult.Version.ToString();
dados += "&FotoURL=";

Related

while export to pdf using itexsharp it shows blank page

i made one desktop application using asp.net which convert html to PDF.
basically this application used for generate users PDF from database.
process: first of all i am converting all data to html and then convert to PDF using itextsharp but after generating some PDFs it shows blank pages
any idea or anyone face this type of issue
public static void converttopdf(string HtmlStream, List<Tuple<string, string>> tifffiles, List<Tuple<string, string>> pdffilestomerge, string filename, string patientfirstpagestr, string TableofContent, string patientheader, SqlConnection con, string sectiondetails)
{
MemoryStream msOutput = new MemoryStream();
TextReader reader = new StringReader(HtmlStream);
Document document = new Document(PageSize.A4, 30, 30, 42, 44);
string filetogenerate = string.Empty;
if (pdffilestomerge != null && pdffilestomerge.Count > 1)
{
filetogenerate = temppath + filename + "_Temp1.pdf";
}
else
{
filetogenerate = temppath + filename + "_Temp.pdf";
}
PdfWriter writer = PdfWriter.GetInstance(document, new System.IO.FileStream(filetogenerate, System.IO.FileMode.Create));
HTMLWorker worker = new HTMLWorker(document);
document.Open();
worker.StartDocument();
string[] separator = new string[] { #"<br clear='all' style='page-break-before:always'>" };
string[] pages = HtmlStream.Split(separator, StringSplitOptions.None);
foreach (string page in pages)
{
document.NewPage();
System.Collections.ArrayList htmlarraylist = HTMLWorker.ParseToList(new StringReader(page), null);
for (int k = 0; k < htmlarraylist.Count; k++)
{
document.Add((IElement)htmlarraylist[k]);
}
}
using (var ms = new MemoryStream())
{
if (tifffiles != null)
{
int docid = 0;
foreach (var obj in tifffiles)
{
string filepath = obj.Item2.ToString();
WriteLogEntry("bitmap file path : " + filepath);
if (filepath != string.Empty)
{
try
{
Bitmap myBitmap = new Bitmap(filepath);
System.Drawing.Color pixelColor = myBitmap.GetPixel(50, 50);
if (pixelColor.Name == "ff808080")
{
WriteLogEntry("convert image by irfanview :" + filepath);
LaunchCommandLineApp(filepath, temppath + "Test.jpg");
document.NewPage();
var imgStream = GetImageStream(temppath + "Test.jpg");
var image = iTextSharp.text.Image.GetInstance(imgStream);
image.SetAbsolutePosition(10, 80);
image.ScaleToFit(document.PageSize.Width - 60, document.PageSize.Height - 80);
//image.ScaleToFit(document.PageSize.Width - 30, document.PageSize.Height);
if (docid != Convert.ToInt32(obj.Item1))
{
Chunk c1 = new Chunk("#~#DID" + obj.Item1.ToString() + "#~#");
c1.Font.SetColor(0, 0, 0); //#00FFFFFF
c1.Font.Size = 0;
document.Add(c1);
}
document.Add(image);
File.Delete(temppath + "Test.jpg");
}
else
{
document.NewPage();
var imgStream = GetImageStream(filepath);
var image = iTextSharp.text.Image.GetInstance(imgStream);
image.SetAbsolutePosition(10, 80);
image.ScaleToFit(document.PageSize.Width - 60, document.PageSize.Height - 80);
//image.ScaleToFit(document.PageSize.Width - 30, document.PageSize.Height);
if (docid != Convert.ToInt32(obj.Item1))
{
Chunk c1 = new Chunk("#~#DID" + obj.Item1.ToString() + "#~#");
c1.Font.SetColor(0, 0, 0); //#00FFFFFF
c1.Font.Size = 0;
document.Add(c1);
}
document.Add(image);
WriteLogEntry("Image added successfully" + filepath);
}
}
catch
{
document.NewPage();
if (docid != Convert.ToInt32(obj.Item1))
{
Chunk c1 = new Chunk("#~#DID" + obj.Item1.ToString() + "#~#");
c1.Font.SetColor(0, 0, 0); //#00FFFFFF
c1.Font.Size = 0;
document.Add(c1);
}
WriteLogEntry("Image not valid" + filepath);
}
docid = Convert.ToInt32(obj.Item1);
}
}
}
}
worker.EndDocument();
worker.Close();
document.Close();
if (pdffilestomerge != null && pdffilestomerge.Count > 1)
{
string file = temppath + filename + "_Temp.pdf";
mergepdf(file, pdffilestomerge, filetogenerate);
}
PdfReader pdfreader = new PdfReader(temppath + filename + "_Temp.pdf");
Document document1 = new Document(PageSize.A4, 30, 30, 42, 44);
PdfWriter writer1 = PdfWriter.GetInstance(document1, new FileStream(FinalOutputPath + filename + ".pdf", FileMode.Create));
//HeaderFooter footer = new HeaderFooter(new Phrase("Page "), true);
//footer.Alignment = Element.ALIGN_RIGHT;
//footer.Border = iTextSharp.text.Rectangle.NO_BORDER;
//document1.Footer = footer;
//HeaderFooter header = new HeaderFooter(new Phrase(""), true);
//header.Alignment = Element.ALIGN_LEFT;
//header.Border = iTextSharp.text.Rectangle.NO_BORDER;
//document1.Add(header);
document1.Open();
PdfContentByte cb1 = writer1.DirectContent;
PdfImportedPage page1;
string test1 = TableofContent; int TableofContentPageCount = 0; int SectionPageStartNumber = 0;
string lastdocnamestr = "";
for (int t = 1; t <= pdfreader.NumberOfPages; t++)
{
document1.NewPage();
HeaderFooter header = new HeaderFooter(new Phrase(""), true);
header.Alignment = Element.ALIGN_LEFT;
header.Border = iTextSharp.text.Rectangle.NO_BORDER;
HeaderFooter header1 = new HeaderFooter(new Phrase(" "), true);
header1.Alignment = Element.ALIGN_LEFT;
header1.Border = iTextSharp.text.Rectangle.NO_BORDER;
HeaderFooter header2 = new HeaderFooter(new Phrase(" "), true);
header2.Alignment = Element.ALIGN_LEFT;
header2.Border = iTextSharp.text.Rectangle.NO_BORDER;
document1.Add(header);
document1.Add(header1);
document1.Add(header2);
page1 = writer1.GetImportedPage(pdfreader, t);
var baseFont = BaseFont.CreateFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
byte[] pdfcontent = pdfreader.GetPageContent(t);
//PdfDictionary dict = pdfreader.GetPageN(t);
string contentStream = System.Text.Encoding.Default.GetString(pdfcontent);
var contentByte = writer1.DirectContent;
contentByte.BeginText();
contentByte.SetFontAndSize(baseFont, 8);
var multiLineString = "";
var multiLineString1 = "";
string test = getBetween(contentStream, "#~#", "#~#");
if (test.Length > 0)
{
test1 = test1.Replace(test + ".", t.ToString());
DataTable dt = getdocdetailforheader(Convert.ToInt32(test.Replace("DID", "")), con);
if (dt.Rows.Count > 0)
{
multiLineString = dt.Rows[0]["DocumentName"].ToString() + " - " + Convert.ToDateTime(dt.Rows[0]["EncounterDTTM"].ToString()).ToString("MM/dd/yyyy") + " | Owner : " + dt.Rows[0]["Ownername"].ToString();
lastdocnamestr = multiLineString;
WriteLogEntry(multiLineString);
}
if (TableofContentPageCount == 0)
{
TableofContentPageCount = t;
}
}
//if (contentStream.Contains("sectionstart") && SectionPageStartNumber == 0) SectionPageStartNumber = t;
if (lastdocnamestr != string.Empty)
{
multiLineString = lastdocnamestr;
}
//else
//{
// if (TableofContentPageCount == 0)
// {
// multiLineString = "Table of Content";
// }
//}
multiLineString1 = patientheader;
contentByte.ShowTextAligned(PdfContentByte.ALIGN_LEFT, multiLineString, 15, 820, 0);
contentByte.ShowTextAligned(PdfContentByte.ALIGN_LEFT, multiLineString1, 15, 810, 0);
contentByte.EndText();
string relLogo = Directory.GetCurrentDirectory().ToString().Replace("bin", "").Replace("Debug", "").Replace("\\\\", "") + "\\Image\\MFA_LOGO.png";
iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(relLogo);
jpg.ScaleAbsolute(38f, 38f);
jpg.SetAbsolutePosition(document1.PageSize.Width - 70, 806);
jpg.Alignment = Element.ALIGN_RIGHT;
document1.Add(jpg);
cb1.MoveTo(0, 805);
cb1.LineTo(document1.PageSize.Width, 805);
cb1.Stroke();
cb1.AddTemplate(page1, 0, 0);
}
SectionPageStartNumber = pdfreader.NumberOfPages + 1;
System.Collections.ArrayList htmlarraylist1 = HTMLWorker.ParseToList(new StringReader(sectiondetails), null);
document1.NewPage();
for (int k = 0; k < htmlarraylist1.Count; k++)
{
document1.Add((IElement)htmlarraylist1[k]);
}
document1.Close();
FinalPDF(FinalOutputPath + filename + ".pdf", FinalOutputPath + filename + "_1.pdf", patientfirstpagestr, test1, TableofContentPageCount, patientheader, SectionPageStartNumber);
File.Delete(temppath + filename + "_Temp.pdf");

I am working with asp.net and i try to display multiple div dynamically it working but every time display same slider data

#region fillAllData4
private void fillAllData4()
{
clsCategory objCategory = new clsCategory(true);
clsProductMain objProduct = new clsProductMain(true);
objCategory.getDropDownMenu();
objProduct.getProduct();
string str = string.Empty;
int i = 0;
// int j = 0;
if (objCategory.ListclsCategory.Count > 0)
{
for (i = 0; i < objCategory.ListclsCategory.Count; i++)
{
cat.InnerHtml = objCategory.ListclsCategory[0].CategoryName;
cat1.InnerHtml = objCategory.ListclsCategory[1].CategoryName;
cat2.InnerHtml = objCategory.ListclsCategory[2].CategoryName;
cat3.InnerHtml = objCategory.ListclsCategory[3].CategoryName;
string[] filePaths = Directory.GetFiles(Server.MapPath("~/images/Saree/"));
int j = 0;
foreach (string filePath in filePaths)
{
string fileName = Path.GetFileName(filePath);
str += #"<div><div><img class='imges' src='images/Saree/" + fileName + #"' /></div>
<div class='sname'>" + objProduct.ListclsProductMain[j].ProductName + #"</div>
<div class='sname2'>" + objProduct.ListclsProductMain[j].MRP + #"</div></div>";
j++;
}
slider3.InnerHtml = str;
slider4.InnerHtml = str;
slider5.InnerHtml = str;
slider6.InnerHtml = str;
//System.Web.UI.HtmlControls.HtmlGenericControl createDiv =
//new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
//createDiv.ID = "createDiv";
//createDiv.InnerHtml =str;
//this.Controls.Add(createDiv);
}
}
}
#endregion

How to write two Handlers using Switch Case

i wrote two handlers but i need to write now only one handler using switch case how to write i tried but not working. please help me. this is my two handlers code i want that in switch case.please solve this problem
public void ProcessRequest(HttpContext context)
{
string fname = string.Empty;
string ffname = string.Empty;
string m_Result = string.Empty;
DataTable dt = new DataTable();
Guid id = Guid.NewGuid();
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE" || HttpContext.Current.Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
{
string[] testfiles = file.FileName.Split(new char[] { '\\' });
fname = testfiles[testfiles.Length - 1];
}
else
{
fname = file.FileName;
ffname = "~/Adds_uploads/" + fname;
}
string p = Path.GetFileNameWithoutExtension(fname);
fname = Path.Combine(context.Server.MapPath("~/Adds_uploads/"), p);
file.SaveAs(fname + id + Path.GetExtension(ffname));
string dirName1 = new DirectoryInfo(fname).Name;
FileInfo fInfo = new FileInfo(ffname);
String dirName = fInfo.Directory.Name + '/' + dirName1 + id + Path.GetExtension(ffname);
HttpContext.Current.Response.Write(JsonConvert.SerializeObject(dirName));
//RAID = context.Request.QueryString["RA_ID"].ToString();
//UploadFileToDB(file, RAID);
}
}
}
public bool IsReusable {
get {
return false;
}
}
2nd Handler
public void ProcessRequest(HttpContext context)
{
string fname = string.Empty;
string ffname = string.Empty;
string m_Result = string.Empty;
DataTable dt = new DataTable();
Guid id = Guid.NewGuid();
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE" || HttpContext.Current.Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
{
string[] testfiles = file.FileName.Split(new char[] { '\\' });
fname = testfiles[testfiles.Length - 1];
}
else
{
fname = file.FileName;
ffname = "~/Fileuploads/" + fname;
}
string p = Path.GetFileNameWithoutExtension(fname);
fname = Path.Combine(context.Server.MapPath("~/Fileuploads/"), p);
file.SaveAs(fname + id + Path.GetExtension(ffname));
string dirName1 = new DirectoryInfo(fname).Name;
FileInfo fInfo = new FileInfo(ffname);
String dirName = fInfo.Directory.Name + '/' + dirName1 + id + Path.GetExtension(ffname);
HttpContext.Current.Response.Write(JsonConvert.SerializeObject(dirName));
//RAID = context.Request.QueryString["RA_ID"].ToString();
//UploadFileToDB(file, RAID);
}
}
}
public bool IsReusable {
get {
return false;
}
}
I think the only difference if the upload path. I would suggest you to pass along another input form the view and then determine the upload path based on that.
i.e
you would have
//for case one
<input type='hidden' name='uploadType' value='files' />
//for case two
<input type='hidden' name='uploadType' value='adds' />
inside your individual file upload forms and then on your action method you can just use
var mappedDirectory = HttpContext.Current.Request.Form["uploadType"].ToString() == "adds" ? "~/Adds_uploads/" : "~/Fileuploads/";
and use this string in your fname construct. So your new method would be like
public void ProcessRequest(HttpContext context)
{
var mappedDirectory = HttpContext.Current.Request.Form["uploadType"].ToString() == "adds" ? "~/Adds_uploads/" : "~/Fileuploads/";
string fname = string.Empty;
string ffname = string.Empty;
string m_Result = string.Empty;
DataTable dt = new DataTable();
Guid id = Guid.NewGuid();
if (context.Request.Files.Count > 0)
{
HttpFileCollection files = context.Request.Files;
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
if (HttpContext.Current.Request.Browser.Browser.ToUpper() == "IE" || HttpContext.Current.Request.Browser.Browser.ToUpper() == "INTERNETEXPLORER")
{
string[] testfiles = file.FileName.Split(new char[] { '\\' });
fname = testfiles[testfiles.Length - 1];
}
else
{
fname = file.FileName;
ffname = mappedDirectory + fname;
}
string p = Path.GetFileNameWithoutExtension(fname);
fname = Path.Combine(context.Server.MapPath(mappedDirectory), p);
file.SaveAs(fname + id + Path.GetExtension(ffname));
string dirName1 = new DirectoryInfo(fname).Name;
FileInfo fInfo = new FileInfo(ffname);
String dirName = fInfo.Directory.Name + '/' + dirName1 + id + Path.GetExtension(ffname);
HttpContext.Current.Response.Write(JsonConvert.SerializeObject(dirName));
//RAID = context.Request.QueryString["RA_ID"].ToString();
//UploadFileToDB(file, RAID);
}
}
}

Cutting and saving video in folder using ffmpeg

private bool ReturnVideo(string fileName)
{
string html = string.Empty;
//rename if file already exists
int j = 0;
string AppPath;
string inputPath;
string outputPath;
// string imgpath;
AppPath = Request.PhysicalApplicationPath;
//Get the application path
inputPath = AppPath + "OriginalVideo";
//Path of the original file
outputPath = AppPath + "ConvertVideo";
//Path of the converted file
// imgpath = AppPath + "Thumbs";
//Path of the preview file
string filepath = Server.MapPath("~/OriginalVideo/" + fileName);
while (File.Exists(filepath))
{
j = j + 1;
int dotPos = fileName.LastIndexOf(".");
string namewithoutext = fileName.Substring(0, dotPos);
string ext = fileName.Substring(dotPos + 1);
fileName = namewithoutext + j + "." + ext;
filepath = Server.MapPath("~/OriginalVideo/" + fileName);
}
try
{
this.fileuploadImageVideo.SaveAs(filepath);
}
catch
{
// return false;
}
string outPutFile;
outPutFile = "~/OriginalVideo/" + fileName;
int i = this.fileuploadImageVideo.PostedFile.ContentLength;
System.IO.FileInfo a = new System.IO.FileInfo(Server.MapPath(outPutFile));
string cmd = "-y -ss 00:00:00 -to 00:00:10 -i " + inputPath + "\\" + fileName + " -vcodec copy -acodec copy " + outputPath + "\\" + fileName.Remove(fileName.IndexOf(".")) + ".mp4";
ConvertNow(cmd);
return true;
}
private void ConvertNow(string cmd)
{
string exepath;
string AppPath = Request.PhysicalApplicationPath;
//Get the application path
exepath = AppPath + "ffmpeg\\ffmpeg.exe";
Process proc = new Process();
proc.StartInfo.FileName = exepath;
//Path of exe that will be executed, only for "filebuffer" it will be "flvtool2.exe"
proc.StartInfo.Arguments = cmd;
//The command which will be executed
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.RedirectStandardOutput = false;
proc.Start();
//while (proc.HasExited == false)
//{
//}
}

MailEnable - Create Account

I'm trying to create an e-mail with MailEnable
based http://www.mailenable.com/developers/NET_SignUp.zip
MailEnable.Administration.Login oLogin = new MailEnable.Administration.Login();
oLogin.Account = iCliente.URL;
oLogin.LastAttempt = -1;
oLogin.LastSuccessfulLogin = -1;
oLogin.LoginAttempts = -1;
oLogin.Password = txt_Senha.Text;
oLogin.Rights = "";
oLogin.Status = -1;
oLogin.UserName = txt_Email + "#" + iCliente.URL;
if (oLogin.GetLogin() != 1)
{
oLogin.LastAttempt = 0;
oLogin.LastSuccessfulLogin = 0;
oLogin.LoginAttempts = 0;
oLogin.Password = txt_Senha.Text;
oLogin.Rights = "USER";
oLogin.Status = 1;
}
MailEnable.Administration.Mailbox mailBoxCreate = new MailEnable.Administration.Mailbox();
mailBoxCreate.Postoffice = iCliente.URL;
mailBoxCreate.MailboxName = txt_Email.Text;
mailBoxCreate.RedirectAddress = txt_Redirect.Text;
mailBoxCreate.RedirectStatus = 0;//recuperar valor da checkbox
mailBoxCreate.Limit = 51200; //-1 for unlimited
mailBoxCreate.Status = 1;
mailBoxCreate.AddMailbox();
MailEnable.Administration.AddressMap mailAMap = new MailEnable.Administration.AddressMap();
mailAMap.Account = iCliente.URL;
mailAMap.DestinationAddress = "[SF:" + iCliente.URL + "/" + txt_Email.Text + "]";
mailAMap.SourceAddress = "[SMTP:" + txt_Email.Text + "#" + iCliente.URL + "]";
mailAMap.AddAddressMap();
But does not work, it creates the email but no password!
:(
Follow my class running perfect.
using System;
using System.Data.SqlClient;
using System.IO;
using System.Xml.XPath;
using MailEnable;
namespace BLL
{
public class MailEnable_Geral
{
public string _Email { get; set; }
public bool CriarEmail(string _senha, string _redirect, long _ativarRedirect)
{
string[] vPostoffice = _Email.Split('#');
string _username = vPostoffice[0];
string _postoffice = vPostoffice[1];
string _domain=_postoffice;
bool _retorno = true;
try
{
MailEnable.Administration.Mailbox mb = new MailEnable.Administration.Mailbox();
mb.Postoffice = _postoffice;
mb.MailboxName = _username;
mb.Host = _domain;
mb.Limit = 51200;//50MB
mb.RedirectAddress = _redirect;
mb.RedirectStatus = _ativarRedirect;//Ativa ou desativa Redirect
mb.Status = 1;
mb.AddMailbox();
MailEnable.Administration.Login login = new MailEnable.Administration.Login();
login.Account = _postoffice;
login.Description = _username + " at " + _domain;
login.Host = _domain;
login.Rights = "USER";
login.Status = 1;
login.Password = _senha;
login.UserName = _username + "#" + _postoffice;
login.AddLogin();
MailEnable.Administration.AddressMap map = new MailEnable.Administration.AddressMap();
map.Account = _postoffice;
map.DestinationAddress = "[SF:" + _postoffice + "/" + _username + "]";
map.SourceAddress = "[SMTP:" + _username + "#" + _domain + "]";
map.Scope = "";
if (map.AddAddressMap() == 0)
{
throw new Exception("Failed address map");
}
}
catch (Exception e)
{
_retorno = false;
}
return _retorno;
}
}
}

Resources