Skip to main content

Posts

Excel Macro to paste all the images in excel book one after the other

Excel Macro to paste all the images in excel book one after the other Dim MyFolder As String, fn As String, i As Long MyFolder = "C:\Pictures\" If Right$(MyFolder, 1) <> "\" Then MyFolder = MyFolder & "\" fn = Dir(MyFolder & "*.jpg") i = 2 Do While fn <> "" Set p = ActiveSheet.Pictures.Insert(MyFolder & fn) p.Top = i i = i + p.Height + 5 fn = Dir() Loop End Sub

Retrive image from database and open in new page using asp.net

Retrive image from database and open in new page using asp.net MemoryStream mstream = new MemoryStream(); SqlConnection conn = new SqlConnection("Data Source=(local)\\sqlexpress;Initial Catalog=master;Integrated Security=True"); conn.Open(); SqlCommand cmd = new SqlCommand("select Image from student1 where Id=" + TextBox1.Text, conn); byte[] image = (byte[])cmd.ExecuteScalar(); mstream.Write(image, 0, image.Length); Bitmap bitmap = new Bitmap(mstream); Response.ContentType = "image/gif"; bitmap.Save(Response.OutputStream, ImageFormat.Gif); conn.Close(); mstream.Close();

C Sharp code for Sending an email

C# code for Sending an email private void send_mail() { MailMessage mm = new MailMessage("write_emailid_reciever", txtEmailId.Text); mm.Subject = "Thnaks for your Feedback."; mm.Body = "Dear Costomer Thanks for your feedback.You are more than welcome to give us a try again. Thank you."; SmtpClient sc = new SmtpClient("mailing_server", 25);//25-is smtp port number NetworkCredential nc = new NetworkCredential(); nc.UserName = "write_emailid_sender"; nc.Password = "password"; sc.Credentials = nc; sc.Send(mm); }

code for resize image in ASP.NET while uploading an image

code for resize image in ASP.NET while uploading an image public bool SaveThumbnailImage(System.Web.UI.WebControls.FileUpload fu, string FullSavePath, int HeightMax, int WidthMax) { try { if (fu.HasFile) { string tmpSaveDir = pg.Server.MapPath("~/TempUploads/"); if (System.IO.Directory.Exists(tmpSaveDir) == false) { System.IO.Directory.CreateDirectory(tmpSaveDir); } string tmpSavePath = pg.Server.MapPath("~/TempUploads/" + fu.FileName); if (System.IO.File.Exists(tmpSavePath)) { try { System.IO.File.Delete(tmpSavePath); } catch { } } fu.SaveAs(tmpSavePath); System.Drawing.Image img = System.Drawing.Image.FromFile(tmpSavePath); double ratioWidth = (double)img.Width / (double)WidthMax; double ratioHeight = (double)img.Height / (double)HeightMax; double ratio = Math.Max(ratioHeight, ratioWidth); int newWidth = (int)(img.Width / ratio); int newHeight = (int)(img.Height / ratio);

C Sharp code for encription and decription of password or text

C# code of encription and decription following are two functions. one for encryption and second for decryption. textbox3 is text box to input data and textbox4 is textbox shows encrypted data. private void encrypt() { int i = 0; string result = ""; string old = textBox3.Text; do { result = result + Convert.ToChar(Convert.ToInt32(old) + (i + 2)); i = i + 1; } while (i < old.Length); textBox4.Text = result; textBox3.Text =""; } private void decrypt() { int i = 0; string result = ""; string old = textBox4.Text; do { result = result + Convert.ToChar(Convert.ToInt32(old) - (i + 2)); i = i + 1; } while (i < old.Length); textBox3.Text = result; textBox4,Text=""; }

How to send data at Business Logic layer by repository pattern

Core--> interfaces, entities, helpers, constants etc Data-->responsible for fetching data from DB. mostly returns Data Table Data Sets--> if m using LINQ, this would be the Data Context Service--> Converts Data Table etc into Entities . Application --> Knows how to deal with entities . show them manipulate them send them back and forth .  insert data using Service layer . If you  find this pattern more flexible .. you could write multiple Data layers that could fetch data from more than one kind of DB and use what you want. If you want to write Data layer that targets more than one kind of DB types (Oracle, Sql, MySql) with little code change then you can use the provider pattern.

Change textbox color if textbox is empty in asp.net using c#

Change textbox color if textbox is empty in asp.net using c# private void button1_Click(object sender, EventArgs e) { textBox1.BackColor = Color.White; textBox2.BackColor = Color.White; textBox3.BackColor = Color.White; textBox4.BackColor = Color.White; string[] text = new string[4]; text[0] = System.Convert.ToString(textBox1.Text); text[1] = System.Convert.ToString(textBox2.Text); text[2] = System.Convert.ToString(textBox3.Text); text[3] = System.Convert.ToString(textBox4.Text); for (int i = 0; i <= 3; i++) { if (text == "") { errorshow(i); } } } private void errorshow(int k) { switch (k) { case 0: textBox1.BackColor = Color.Red; break; case 1: textBox2.BackColor = Color.Red; break; case 2: textBox3.BackColor = Color.Red; break; case 3: textBox4.BackColor = Color.Red; break; } }