.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Upload transparent PNG image

Posted By:      Posted Date: August 21, 2010    Points: 0   Category :ASP.Net

Hi everybody

I'm creating a website where it must  be able to upload, crop and resize images. This works until I use transparent PNG images. When I upload a transparent PNG, the transparency becomes black. I've searched the whole internet, but found no solution so far. Can someone help me? This is my code. I'm working with MVC 2.

			try {
				HttpPostedFileBase file = Request.Files["image"];
				file.SaveAs(Server.MapPath("/Uploads/" + file.FileName));

				ViewData["ImageLocation"] = "/Uploads/" + file.FileName;
				return View();
			catch (Exception exc) {
				return RedirectToAction("UploadImage");

View Complete Post

More Related Resource Links

ASP.Net Upload Image to MS Access Database

As you learnt from the previous articles to upload image to the SQL Database in ASP.Net 2.0 and stream that image into the memory to retrieve it from the database and display it on the web page. In this article you will learn how to upload images to the MS Access database in ASP.Net 2.0

First of all create an Access Database and place it in the App_Data folder of ASP.Net web site project. Then create a table "tblImg" with the following fields:

How to upload image in Mobile Application?


I have requirement to upload the image in mobile Web application using asp.net. For this I have add mobile templates but regarding to image there is no any file upload control. Then I see one article and use the below code:

<mobile:DeviceSpecific ID="DeviceSpecific1" Runat="server">
                <input style="width: 389px; height: 22px" type="file" size="45" runat="server" id="FileUpload1">

Transparent image

Is there any way in which image background can be made transparent? Thanks,Krunal C

Need to upload images with data, but image url's are in separate db table

Hello, I'm making a simple homes classifieds section and when a home ad is created, a HomeID is automatically created for it in the db.  I need the images to upload and enter the associated HomeID with each image automatically.  What I tried isn't working, because it looks like it's looking for the HomeID in the codebehind before it gets entered into the db.ASPX CODE<asp:SqlDataSource ID="SqlDataSource1" runat="server"         ConnectionString="<%$ ConnectionStrings:ConnectionString %>"         InsertCommand="INSERT INTO [Homes] ([UserName], [Street], [Details], [Contact], [Phone], , [Thumb], [Price], [Approved], [Posted]) VALUES (@UserName, @Street, @Details, @Contact, @Phone, @Email, @Thumb, @Price, @Approved, @Posted)"         SelectCommand="SELECT [HomeID], [UserName], [Street], [Details], [Contact], [Phone], , [Thumb], [Price], [Approved], [Posted] FROM [Homes]" >        <InsertParameters>            <asp:Parameter Name="UserName" Type="String" />            <asp:Parameter Name="Street" Type="Str

Image upload not working in updatepanel

Hi, in my update panel i need to upload a image.my Fileupload control within update panel.so when i check is it correct format or not in following code then it always take else part. Dim fileUpload1 As FileUpload = CType(Me.FindControl("FileUpload1"), FileUpload)            'Make sure a file has been successfully uploaded            If fileUpload1.PostedFile Is Nothing OrElse String.IsNullOrEmpty(fileUpload1.PostedFile.FileName) OrElse fileUpload1.PostedFile.InputStream Is Nothing Then                Label1.Text = "Please Upload Valid picture file"                Exit Sub            End If            'Make sure we are dealing with a JPG or GIF file            Dim extension As String = System.IO.Path.GetExtension(fileUpload1.PostedFile.FileName).ToLower()            Dim MIMEType As String = Nothing            Select Case exte

Upload image to database - couldn't find file path

I'm trying to display images in a GridView (yes, still this...). [edit] Before I can come to that I have to upload some images to the database.I've followed this tutorial for the "upload image to database" code (this worked fine for uploading images, but I don't know if the images were converted to byte):http://aspsnippets.com/Articles/Save-Files-to-SQL-Server-Database-using-FileUpload-Control.aspxand I've followed this tutorial for the "display images in gridview" code (and "retrieve file" from the tutorial below).http://www.aspsnippets.com/Articles/Display-images-from-SQL-Server-Database-in-ASP.Net-GridView-control.aspxIt doesn't quite work, the GridView shows but without imagesNow I'm trying to change the "save file" code according to this tutorial:http://aspsnippets.com/Articles/Save-and-Retrieve-Files-from-SQL-Server-Database-using-ASP.Net.aspxbut I don't understand everything in it. When I try to upload an image I get an error on this line:FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); //couldn't find file (path to image I tried to upload) What should I do about it?

rezise image on upload

Hi have the following method to upload images but I want to resize every image uploaded to 90x40 can anyone help me to edit this code so this will happen cheers   private string UploadFile(string pathToSave, FileUpload uploadfile)        {            string strFileName;            string strFilePath;            string strFolder;            string file_version = "";            strFolder = Server.MapPath("~/images/" + pathToSave);             // Retrieve the name of the file that is posted.            strFileName = uploadfile.PostedFile.FileName;            strFileName = Path.GetFileName(strFileName);             if (uploadfile.HasFile)            {                // Create the folder if it does no

image upload????

in my project the client will upload his image that image should apper in the image box how can i do this???

Show image after upload at same time

I want to show uploaded image at same moment. I use this code: protected void FileUploadLaptop_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e) { ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "size", "top.$get(\"" + lblErrorMessage.ClientID + "\").innerHTML = 'Uploaded size: " + FileUploadLaptop.FileBytes.Length.ToString() + "';", true); string savePath = MapPath("~/Uploads/" + System.IO.Path.GetFileName(e.filename)); FileUploadLaptop.SaveAs(savePath); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "image", "top.$get(\"" + imgLaptop.ClientID + "\").src = 'Uploads/" + System.IO.Path.GetFileName(e.filename) + "';", true); imgLaptop.ImageUrl = savePath; imgLaptop.DataBind(); } *** Picture upload to path but image control doesn't show it. what is wrong?

Rebind datalist after upload an image using jquery


Hi, I'm having a problem with using jquery to trigger a datalist rebind here, hope people here could help me with it. 

I'm using a jquery plugin called uploadify to upload images to my database. I'd like my datalist to be auto-rebind after the images' been uploaded so people could see the changes immediately. Also because this is a feature for admin there is a delete button in the datalist. I used updatePanel for this.  

I put __doPostBack('" + upnlUploaded.ClientID + "','') to the javascript so when Images have been uploaded the update panel will postback. 

I also have the following two lines to make it working... 

<asp:UpdatePanel ID="upnlUploaded" runat="server" UpdateMode="Conditional" OnLoad="upnlUploaded_Load"> <%--upnlUploaded_Load   --%>

       <asp:UpdatePanel ID="upnlUploaded" runat="server" UpdateMode="Conditional" OnLoad="upnlUploaded_Load"

        protected void upnlUploaded_Load(object sender, EventArgs e)

How to make GIF image transparent on windows form app


I got transparent image saved in GIF format, and I want to put this image on other image. The problem is that this gif image is not transparet anymore when I use picturebox or pannel. I also set BackColor to transparent, but it not works :S ... here example:


That white background needs to be transparent .. how can I do that?

I'm using Microsoft Visual C# 2010 Express

Image Upload Fails- access denied to folder


i am trying to use a fileopen dialog to select an image and copy it to my project folder .

i have used this code to do that.

OpenFileDialog ofd = new OpenFileDialog();
      ofd.Filter = "All Image Files| *.*";
          imgImagePath.Source=new BitmapImage(new Uri(ofd.FileName,UriKind.RelativeOrAbsolute));
          FileStream fs = new FileStream(ofd.FileName,FileMode.Open,FileAccess.Read);
          FileStream copyfs = new FileStream(@"../../Themes/Images", FileMode.CreateNew, FileAccess.Write);

The Error i am gettin is The so and so folder access is denied.

I have check that the folder is not read only. and its in d:

Any suggestions?


how to validate picture library to upload only image files?



how to validate "Picture library" to upload only image files. Currently now it is accepting .doc,.txt files etc.

Is there any way to overcome this issue?




on file upload image preview in asp.net



when  a Image is uploaded immediately the image preview should display in image control or html image in asp.net.

I try but in all browsers its not working.

pls tell me how to do this task and the image preview should display in all browsers.

Many Thanks in Advance.

DetailsView Image Resize on Upload


I am using a details view to add a name and image path to a database. I have a template with a fileupload control and a dropdown list (landscape and portrait), that is used to get the file name. My question is: How can I resize the image based upon whether the image is landscape or portrait? This is my code so far:

<%@ Page Title="" Language="VB" MasterPageFile="~/Admin.master" AutoEventWireup="false" CodeFile="UploadGallery.aspx.vb" Inherits="Admin_UploadGallery" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<h1>NTTC Administration: Upload Pictures to Gallery</h1>
    <asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="318px" 
        AutoGenerateRows="False" DataKeyNames="ID" DataSourceID="SqlDataSource1" 
        DefaultMode="Insert" GridLines="None">
            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" 
                ReadOnly="True" Sor

Sharepoint upload image, upload to missing items



When I access my site with address like in central administration (ex: mysite:7777) list of "upload to" does not contain all elements. It only consists of images, documents and pages.  (I upload from some page, edit and then insert image from computer)


When I access my site with ip address (ex: or other address configured in hosts) I can see all items. There are additionally site collection images, sc pages etc. 

I want to see all items when accessing site with address.

Any ideas?




image upload via DataFormWebPart



I have a list with a DataFormWebPart that is loading associated images from a corresponding picture library. When enabling "show insert item link" in Sharepoint Designer for this web part, the link is added and when clicked shows the picture upload form from within the WebPart as expected. After choosing the image to upload, I hit save and get a "The data source control failed to execute the insert command" error.

Any suggestions as to how I can fix this? Essentially I'm attempting to be in this list and upload a photo to a corresponding picture library on the same site.

I'm using WSS3.



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend