Skip to main content

Image Upload!

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 :-


Comments

Popular posts from this blog

URL Rewritting

http://www.simple-talk.com/dotnet/asp.net/a-complete-url-rewriting-solution-for-asp.net-2.0/ http://msdn.microsoft.com/en-us/library/ms972974.aspx URL Rewriting in ASP.NET Summary: Examines how to perform dynamic URL rewriting with Microsoft ASP.NET. URL rewriting is the process of intercepting an incoming Web request and automatically redirecting it to a different URL. Discusses the various techniques for implementing URL rewriting, and examines real-world scenarios of URL rewriting. (31 printed pages) Download the source code for this article. Contents Introduction Common Uses of URL Rewriting What Happens When a Request Reaches IIS Implementing URL Rewriting Building a URL Rewriting Engine Performing Simple URL Rewriting with the URL Rewriting Engine Creating Truly "Hackable" URLs Conclusion Related Books Introduction Take a moment to look at some of the URLs on your website. Do you find URLs like http://yoursite.com/info/dispEmployeeInfo.aspx?EmpID=459-099&type=summ...

SEND A PDF FILE AS AN ATTACHEMENT OF MAIL!

System.Net.Mail.MailMessage m1 = new System.Net.Mail.MailMessage(); m1.From = "manpreet@gmail.com" m1.Subject = "Test mail "; m1.Body = str.ToString(); m1.IsBodyHtml = true; m1.To.Add("jasdeep@gmail.com"); m1.CC.Add("jasdeep123@gmail.com"); m1.Attachments.Add(new Attachment(strserverpath + @"\pdf\" + PdfFileName)); smtp.Send(m1);

Sql Server Tips

IF WE WANT TO SELECT  TOP N ROWS  FROM A TABLE ,  WE USE THE FETCH NEXT  SELECT    * FROM  table1   ---//First m rows ignore first n rows ORDER BY id OFFSET n ROWS FETCH NEXT m ROWS ONLY if n=0, m=10 then first  10 rows if n=10, m=10 then first  10 rows start from 11th row Row_number()   SELECT  ROW_NUMBER() OVER(order by db.id) Insertion Simultaneouly in temp table with output clause DECLARE @table1 table (   Id int,   name nvarchar(50) ); DECLARE @table2 table (  Id int,  name nvarchar(50) ); INSERT INTO @table2 OUTPUT INSERTED.*   INTO @table1   select top 10 id, name  from FinalTable SELECT * FROM @table2; SELECT * FROM @table1;