Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to upload asp.net Images

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "ASP.NET picture upload method tutorial," interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "ASP.NET picture upload method tutorial" bar!

First, upload the picture, the code is as follows:

xxx.aspx

The copy code is as follows:

xxx.aspx.cs

The copy code is as follows:

protected void Button2_Click(object sender, EventArgs e)

{

for (int i = 0; i

< Request.Files.Count; i++) { HttpPostedFile file = Request.Files[i]; if (file.ContentLength >

0)

{

if (file.ContentType.Contains("image/"))

{

using (System.Drawing.Image img = System.Drawing.Image.FromStream(file.InputStream))

{

using (Graphics g = Graphics.FromImage(img))

{

g.DrawString("My Picture", new Font("Song", 14), Brushes.Red, 0, 0);

}

string FileName = System.IO.Path.GetFileName(file.FileName);

string[] SplitFileName = FileName.Split('. ');

string AtterFileName = DateTime.Now.ToString("yyyMMddHHmmss") + ". " + SplitFileName[1];

img.Save(Server.MapPath("/upload/" + AtterFileName));

this.Image2.ImageUrl = "upload/" + AtterFileName;

}

}

else

{

Response.Write("alert ('This file is not in picture format! ');");

}

}

else

{

Response.Write("alert ('Please select pictures to upload');");

}

}

}

Third, add the image watermark image upload, the code is as follows:

xxx.aspx

The copy code is as follows:

xxx.aspx.cs

The copy code is as follows:

protected void Button4_Click(object sender, EventArgs e)

{

for (int i = 0; i

< Request.Files.Count; i++) { HttpPostedFile file = Request.Files[i]; if (file.ContentLength >

0)

{

if (file.ContentType.Contains("image/"))

{

using (System.Drawing.Image img = System.Drawing.Image.FromStream(file.InputStream))

{

using (System.Drawing.Image imgThumb = new Bitmap(200, 100))

{

using (Graphics g = Graphics.FromImage(imgThumb))

{

g.DrawImage(img, new Rectangle(0, 0, imgThumb.Width, imgThumb.Height), new Rectangle(0, 0, img.Width, img.Height), GraphicsUnit.Pixel);

}

string fileName = file.FileName;

string[] SplitFileName = fileName.Split('. ');

string AtterFileName = DateTime.Now.ToString("yyyMMddHHmmss") + ". " + SplitFileName[1];

img.Save(Server.MapPath("/upload/" + AtterFileName));

this.Image4.ImageUrl = "upload/" + AtterFileName;

}

}

}

else

{

Response.Write("alert ('This file is not in picture format! ');");

}

}

else

{

Response.Write("alert ('Please select pictures to upload');");

}

}

}

At this point, I believe we have a deeper understanding of the "ASP.NET picture upload method tutorial," may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report