File Uploading :-
if (FileUpdThumbImage.PostedFile.ContentLength > 0)
{
if (FileUpdThumbImage.PostedFile.ContentLength > Convert.ToInt32(ConfigurationManager.AppSettings["DesignThumImageSize"]))
{
lblMsg.Text = GetLocalResourceObject("strMsgSizeThumb").ToString();
return;
}
string StrImagenameThumb;
Boolean blnFileUpload;
//User Id is taken as static
blnFileUpload = SaveImageThumbOnFileSystem(UserID, FileUpdThumbImage, "Design", out StrImagenameThumb);
if (blnFileUpload== false )
{
lblMsg.Visible = true;
lblMsg.Text = GetLocalResourceObject("strMsgCheckthumb").ToString();
return;
}
prop.DesignThumbImg = StrImagenameThumb;
}
creating Directory image Server:-
public Boolean SaveImageThumbOnFileSystem(Guid _userid, System.Web.UI.WebControls.FileUpload FileUpload1, String FolderName, out String ImageName)
{
ImageName = "";
if (FileUpload1.PostedFile.ContentLength != 0)
{
string strImage = FileUpload1.PostedFile.FileName;
Int32 i = strImage.LastIndexOf('\\');
string strSub = strImage.Substring(i + 1);
Int32 TotalLength = strSub.Length;
Int32 FileLength = strSub.LastIndexOf('.');
string strExtension = strSub.Substring(FileLength + 1, TotalLength - (FileLength + 1));
strExtension = strExtension.ToLower();
if (strExtension == "jpg" || strExtension == "gif" || strExtension == "jpeg" || strExtension == "png")
{
Random rnd = new Random();
string imagename = DateTime.Now.Ticks + rnd.Next().ToString().Substring(0, 1);
string strImageName = imagename + "." + strExtension;
string strPath = ConfigurationManager.AppSettings["InsertImagePath"];
if (!Directory.Exists(strPath + "\\" + _userid))
{
Directory.CreateDirectory(strPath + "\\" + _userid);
}
if (!Directory.Exists(strPath + "\\" + _userid + "\\" + FolderName))
{
Directory.CreateDirectory(strPath + "\\" + _userid + "\\" + FolderName);
}
string target = ConfigurationManager.AppSettings["InsertImagePath"] + "/" + _userid + "/" + FolderName + "/";
string strImageThumbName = target + strImageName;
ImageName = strImageName;
FileUpload1.SaveAs(strImageThumbName);
//File.Delete(strImageThumbName);
string GetThumbnail = ConfigurationManager.AppSettings["GetImagePathDesign"] + "/" + _userid + "/" + FolderName + "/" + ImageName;
FileInfo fileInfo = new FileInfo(GetThumbnail);
System.Drawing.Image imgOriginal = null;
imgOriginal = System.Drawing.Image.FromFile(fileInfo.FullName);
int width, height;
width = imgOriginal.Width;
height = imgOriginal.Height;
if (width > 100 || height > 70)
{
fileInfo = null;
imgOriginal = null;
lblMsg.Text = GetLocalResourceObject("strMsgCheckthumb").ToString();
//File.Delete(strImageThumbName);
return false;
}
else if (width < 100 || height < 70)
{
fileInfo = null;
imgOriginal = null;
lblMsg.Text = GetLocalResourceObject("strMsgCheckthumb1").ToString();
return false;
}
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
Web Config Key Setting :-
if (FileUpdThumbImage.PostedFile.ContentLength > 0)
{
if (FileUpdThumbImage.PostedFile.ContentLength > Convert.ToInt32(ConfigurationManager.AppSettings["DesignThumImageSize"]))
{
lblMsg.Text = GetLocalResourceObject("strMsgSizeThumb").ToString();
return;
}
string StrImagenameThumb;
Boolean blnFileUpload;
//User Id is taken as static
blnFileUpload = SaveImageThumbOnFileSystem(UserID, FileUpdThumbImage, "Design", out StrImagenameThumb);
if (blnFileUpload== false )
{
lblMsg.Visible = true;
lblMsg.Text = GetLocalResourceObject("strMsgCheckthumb").ToString();
return;
}
prop.DesignThumbImg = StrImagenameThumb;
}
creating Directory image Server:-
public Boolean SaveImageThumbOnFileSystem(Guid _userid, System.Web.UI.WebControls.FileUpload FileUpload1, String FolderName, out String ImageName)
{
ImageName = "";
if (FileUpload1.PostedFile.ContentLength != 0)
{
string strImage = FileUpload1.PostedFile.FileName;
Int32 i = strImage.LastIndexOf('\\');
string strSub = strImage.Substring(i + 1);
Int32 TotalLength = strSub.Length;
Int32 FileLength = strSub.LastIndexOf('.');
string strExtension = strSub.Substring(FileLength + 1, TotalLength - (FileLength + 1));
strExtension = strExtension.ToLower();
if (strExtension == "jpg" || strExtension == "gif" || strExtension == "jpeg" || strExtension == "png")
{
Random rnd = new Random();
string imagename = DateTime.Now.Ticks + rnd.Next().ToString().Substring(0, 1);
string strImageName = imagename + "." + strExtension;
string strPath = ConfigurationManager.AppSettings["InsertImagePath"];
if (!Directory.Exists(strPath + "\\" + _userid))
{
Directory.CreateDirectory(strPath + "\\" + _userid);
}
if (!Directory.Exists(strPath + "\\" + _userid + "\\" + FolderName))
{
Directory.CreateDirectory(strPath + "\\" + _userid + "\\" + FolderName);
}
string target = ConfigurationManager.AppSettings["InsertImagePath"] + "/" + _userid + "/" + FolderName + "/";
string strImageThumbName = target + strImageName;
ImageName = strImageName;
FileUpload1.SaveAs(strImageThumbName);
//File.Delete(strImageThumbName);
string GetThumbnail = ConfigurationManager.AppSettings["GetImagePathDesign"] + "/" + _userid + "/" + FolderName + "/" + ImageName;
FileInfo fileInfo = new FileInfo(GetThumbnail);
System.Drawing.Image imgOriginal = null;
imgOriginal = System.Drawing.Image.FromFile(fileInfo.FullName);
int width, height;
width = imgOriginal.Width;
height = imgOriginal.Height;
if (width > 100 || height > 70)
{
fileInfo = null;
imgOriginal = null;
lblMsg.Text = GetLocalResourceObject("strMsgCheckthumb").ToString();
//File.Delete(strImageThumbName);
return false;
}
else if (width < 100 || height < 70)
{
fileInfo = null;
imgOriginal = null;
lblMsg.Text = GetLocalResourceObject("strMsgCheckthumb1").ToString();
return false;
}
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
Web Config Key Setting :-
Comments