Tuesday, November 24, 2009
SMTP Server
To fix this, we will have to make sure that no other mailservers are running. Then we have to startup SMTP service (via services). After which, Inside Manager Server, "Manage Mail Server", "add a POP3 acccount". Use that as the default SMTP details.
Automatic Thumbnail C#
HtmlTable dTable = new HtmlTable();
dTable.Width = "500px";
dTable.CellPadding = 2;
dTable.CellSpacing = 0;
dTable.Border = 0;
int col = 5;
HtmlTableRow dTRow = new HtmlTableRow();
for (int count = 0; count < tmp.Length; count++)
{
if ((count % col == 0) && (count != 0))
{
dTable.Controls.Add(dTRow);
dTRow = new HtmlTableRow();
}
HtmlTableCell dTCell = new HtmlTableCell();
Photo result = tmp[count];
dTCell.InnerHtml = "
";
dTRow.Controls.Add(dTCell);
}
dTable.Controls.Add(dTRow);
Panel1.Controls.Add(dTable);
dTable.Width = "500px";
dTable.CellPadding = 2;
dTable.CellSpacing = 0;
dTable.Border = 0;
int col = 5;
HtmlTableRow dTRow = new HtmlTableRow();
for (int count = 0; count < tmp.Length; count++)
{
if ((count % col == 0) && (count != 0))
{
dTable.Controls.Add(dTRow);
dTRow = new HtmlTableRow();
}
HtmlTableCell dTCell = new HtmlTableCell();
Photo result = tmp[count];
dTCell.InnerHtml = "
";
dTRow.Controls.Add(dTCell);
}
dTable.Controls.Add(dTRow);
Panel1.Controls.Add(dTable);
C# SQL Encode/Decode
public string SqlEncode(string inStr)
{
inStr = inStr.Replace("'", "''");
inStr = inStr.Replace("<", "<");
inStr = inStr.Replace(">", ">");
return inStr;
}
public string SqlDecode(string inStr)
{
if (inStr == "")
return null;
inStr = inStr.Replace("''", "'");
inStr = inStr.Replace("<", "<");
inStr = inStr.Replace(">", ">");
return inStr;
}
{
inStr = inStr.Replace("'", "''");
inStr = inStr.Replace("<", "<");
inStr = inStr.Replace(">", ">");
return inStr;
}
public string SqlDecode(string inStr)
{
if (inStr == "")
return null;
inStr = inStr.Replace("''", "'");
inStr = inStr.Replace("<", "<");
inStr = inStr.Replace(">", ">");
return inStr;
}
C# Binary Image Upload
// adapted from http://snippets.dzone.com/posts/show/1485
public static byte[] ResizeImageFile(byte[] imageFile, int targetSize)
{
System.Drawing.Image original = System.Drawing.Image.FromStream(new MemoryStream(imageFile));
int targetH, targetW;
if (original.Height > original.Width)
{
targetH = targetSize;
targetW = (int)(original.Width * ((float)targetSize / (float)original.Height));
}
else
{
targetW = targetSize;
targetH = (int)(original.Height * ((float)targetSize / (float)original.Width));
}
System.Drawing.Image imgPhoto = System.Drawing.Image.FromStream(new MemoryStream(imageFile));
// Create a new blank canvas. The resized image will be drawn on this canvas.
Bitmap bmPhoto = new Bitmap(targetW, targetH, PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(72, 72);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.SmoothingMode = SmoothingMode.AntiAlias;
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;
grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality;
grPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, targetW, targetH), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel);
// Save out to memory and then to a file. We dispose of all objects to make sure the files don't stay locked.
MemoryStream mm = new MemoryStream();
bmPhoto.Save(mm, System.Drawing.Imaging.ImageFormat.Jpeg);
original.Dispose();
imgPhoto.Dispose();
bmPhoto.Dispose();
grPhoto.Dispose();
return mm.GetBuffer();
}
public int uploadImage()
{
int photonum = 1;
Stream imgStream = UploadFile.PostedFile.InputStream;
int imgLen = UploadFile.PostedFile.ContentLength;
string imgContentType = UploadFile.PostedFile.ContentType;
byte[] imgBinaryData = new byte[imgLen];
int n = imgStream.Read(imgBinaryData, 0, imgLen);
byte[] imgBinaryData2 = ResizeImageFile(imgBinaryData, 200);
string imgName = UploadFile.PostedFile.FileName;
int newImageLen = imgBinaryData2.Length;
String cdate = DateTime.Now.ToString();
int RowsAffected = SaveToDB(imgName, imgBinaryData2, imgContentType, newImageLen, cdate);
if (RowsAffected > 0)
{
OleDbDataReader rdr = null;
strConnection = ConfigurationManager.AppSettings["DBKey"];
String strSQL = "SELECT img_id FROM tblImages where created_date='" + cdate + "'";
conUser = new OleDbConnection(strConnection);
if (conUser.State.ToString().Equals("Open")) { conUser.Close(); }
conUser.Open();
cmdUser = new OleDbCommand(strSQL, conUser);
rdr = cmdUser.ExecuteReader();
while (rdr.Read())
{
photonum = rdr.GetInt32(0);
}
return photonum;
}
return -1;
}
public static byte[] ResizeImageFile(byte[] imageFile, int targetSize)
{
System.Drawing.Image original = System.Drawing.Image.FromStream(new MemoryStream(imageFile));
int targetH, targetW;
if (original.Height > original.Width)
{
targetH = targetSize;
targetW = (int)(original.Width * ((float)targetSize / (float)original.Height));
}
else
{
targetW = targetSize;
targetH = (int)(original.Height * ((float)targetSize / (float)original.Width));
}
System.Drawing.Image imgPhoto = System.Drawing.Image.FromStream(new MemoryStream(imageFile));
// Create a new blank canvas. The resized image will be drawn on this canvas.
Bitmap bmPhoto = new Bitmap(targetW, targetH, PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(72, 72);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.SmoothingMode = SmoothingMode.AntiAlias;
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;
grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality;
grPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, targetW, targetH), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel);
// Save out to memory and then to a file. We dispose of all objects to make sure the files don't stay locked.
MemoryStream mm = new MemoryStream();
bmPhoto.Save(mm, System.Drawing.Imaging.ImageFormat.Jpeg);
original.Dispose();
imgPhoto.Dispose();
bmPhoto.Dispose();
grPhoto.Dispose();
return mm.GetBuffer();
}
public int uploadImage()
{
int photonum = 1;
Stream imgStream = UploadFile.PostedFile.InputStream;
int imgLen = UploadFile.PostedFile.ContentLength;
string imgContentType = UploadFile.PostedFile.ContentType;
byte[] imgBinaryData = new byte[imgLen];
int n = imgStream.Read(imgBinaryData, 0, imgLen);
byte[] imgBinaryData2 = ResizeImageFile(imgBinaryData, 200);
string imgName = UploadFile.PostedFile.FileName;
int newImageLen = imgBinaryData2.Length;
String cdate = DateTime.Now.ToString();
int RowsAffected = SaveToDB(imgName, imgBinaryData2, imgContentType, newImageLen, cdate);
if (RowsAffected > 0)
{
OleDbDataReader rdr = null;
strConnection = ConfigurationManager.AppSettings["DBKey"];
String strSQL = "SELECT img_id FROM tblImages where created_date='" + cdate + "'";
conUser = new OleDbConnection(strConnection);
if (conUser.State.ToString().Equals("Open")) { conUser.Close(); }
conUser.Open();
cmdUser = new OleDbCommand(strSQL, conUser);
rdr = cmdUser.ExecuteReader();
while (rdr.Read())
{
photonum = rdr.GetInt32(0);
}
return photonum;
}
return -1;
}
C# Binary Image Upload
// adapted from http://snippets.dzone.com/posts/show/1485
public static byte[] ResizeImageFile(byte[] imageFile, int targetSize)
{
System.Drawing.Image original = System.Drawing.Image.FromStream(new MemoryStream(imageFile));
int targetH, targetW;
if (original.Height > original.Width)
{
targetH = targetSize;
targetW = (int)(original.Width * ((float)targetSize / (float)original.Height));
}
else
{
targetW = targetSize;
targetH = (int)(original.Height * ((float)targetSize / (float)original.Width));
}
System.Drawing.Image imgPhoto = System.Drawing.Image.FromStream(new MemoryStream(imageFile));
// Create a new blank canvas. The resized image will be drawn on this canvas.
Bitmap bmPhoto = new Bitmap(targetW, targetH, PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(72, 72);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.SmoothingMode = SmoothingMode.AntiAlias;
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;
grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality;
grPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, targetW, targetH), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel);
// Save out to memory and then to a file. We dispose of all objects to make sure the files don't stay locked.
MemoryStream mm = new MemoryStream();
bmPhoto.Save(mm, System.Drawing.Imaging.ImageFormat.Jpeg);
original.Dispose();
imgPhoto.Dispose();
bmPhoto.Dispose();
grPhoto.Dispose();
return mm.GetBuffer();
}
public int uploadImage()
{
int photonum = 1;
Stream imgStream = UploadFile.PostedFile.InputStream;
int imgLen = UploadFile.PostedFile.ContentLength;
string imgContentType = UploadFile.PostedFile.ContentType;
byte[] imgBinaryData = new byte[imgLen];
int n = imgStream.Read(imgBinaryData, 0, imgLen);
byte[] imgBinaryData2 = ResizeImageFile(imgBinaryData, 200);
string imgName = UploadFile.PostedFile.FileName;
int newImageLen = imgBinaryData2.Length;
String cdate = DateTime.Now.ToString();
int RowsAffected = SaveToDB(imgName, imgBinaryData2, imgContentType, newImageLen, cdate);
if (RowsAffected > 0)
{
OleDbDataReader rdr = null;
strConnection = ConfigurationManager.AppSettings["DBKey"];
String strSQL = "SELECT img_id FROM tblImages where created_date='" + cdate + "'";
conUser = new OleDbConnection(strConnection);
if (conUser.State.ToString().Equals("Open")) { conUser.Close(); }
conUser.Open();
cmdUser = new OleDbCommand(strSQL, conUser);
rdr = cmdUser.ExecuteReader();
while (rdr.Read())
{
photonum = rdr.GetInt32(0);
}
return photonum;
}
return -1;
}
public static byte[] ResizeImageFile(byte[] imageFile, int targetSize)
{
System.Drawing.Image original = System.Drawing.Image.FromStream(new MemoryStream(imageFile));
int targetH, targetW;
if (original.Height > original.Width)
{
targetH = targetSize;
targetW = (int)(original.Width * ((float)targetSize / (float)original.Height));
}
else
{
targetW = targetSize;
targetH = (int)(original.Height * ((float)targetSize / (float)original.Width));
}
System.Drawing.Image imgPhoto = System.Drawing.Image.FromStream(new MemoryStream(imageFile));
// Create a new blank canvas. The resized image will be drawn on this canvas.
Bitmap bmPhoto = new Bitmap(targetW, targetH, PixelFormat.Format24bppRgb);
bmPhoto.SetResolution(72, 72);
Graphics grPhoto = Graphics.FromImage(bmPhoto);
grPhoto.SmoothingMode = SmoothingMode.AntiAlias;
grPhoto.InterpolationMode = InterpolationMode.HighQualityBicubic;
grPhoto.PixelOffsetMode = PixelOffsetMode.HighQuality;
grPhoto.DrawImage(imgPhoto, new Rectangle(0, 0, targetW, targetH), 0, 0, original.Width, original.Height, GraphicsUnit.Pixel);
// Save out to memory and then to a file. We dispose of all objects to make sure the files don't stay locked.
MemoryStream mm = new MemoryStream();
bmPhoto.Save(mm, System.Drawing.Imaging.ImageFormat.Jpeg);
original.Dispose();
imgPhoto.Dispose();
bmPhoto.Dispose();
grPhoto.Dispose();
return mm.GetBuffer();
}
public int uploadImage()
{
int photonum = 1;
Stream imgStream = UploadFile.PostedFile.InputStream;
int imgLen = UploadFile.PostedFile.ContentLength;
string imgContentType = UploadFile.PostedFile.ContentType;
byte[] imgBinaryData = new byte[imgLen];
int n = imgStream.Read(imgBinaryData, 0, imgLen);
byte[] imgBinaryData2 = ResizeImageFile(imgBinaryData, 200);
string imgName = UploadFile.PostedFile.FileName;
int newImageLen = imgBinaryData2.Length;
String cdate = DateTime.Now.ToString();
int RowsAffected = SaveToDB(imgName, imgBinaryData2, imgContentType, newImageLen, cdate);
if (RowsAffected > 0)
{
OleDbDataReader rdr = null;
strConnection = ConfigurationManager.AppSettings["DBKey"];
String strSQL = "SELECT img_id FROM tblImages where created_date='" + cdate + "'";
conUser = new OleDbConnection(strConnection);
if (conUser.State.ToString().Equals("Open")) { conUser.Close(); }
conUser.Open();
cmdUser = new OleDbCommand(strSQL, conUser);
rdr = cmdUser.ExecuteReader();
while (rdr.Read())
{
photonum = rdr.GetInt32(0);
}
return photonum;
}
return -1;
}
Form does not get value from readonly fields
To fix this, don't put readonly property for the controls by default, do it programatically. This has something to the storage of values for disabled properties. Apparently .NET does not store the value of disabled controls and hence does not pass the value on.
txtStartDate.Attributes.Add("readonly", "readonly");
txtExpDate.Attributes.Add("readonly", "readonly");
txtStartDate.Attributes.Add("readonly", "readonly");
txtExpDate.Attributes.Add("readonly", "readonly");
ASP.NET function calling from HTML
<%# formatColor(DataBinder.Eval(Container.DataItem, "status").ToString()) %>
Subscribe to:
Posts (Atom)