.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

Having trouble cropping an image (w3wp.exe has the file locked).

Posted By:      Posted Date: October 25, 2010    Points: 0   Category :ASP.Net

Hey Guys,

Hoping someone can help im having a real issue with resaving an image (after I get the crop area from a jquery control). I get a GDI error and when I run handle.exe on the file it is open with the w3wp.exe.

I have 2 methods (1 that saves images when they have been uploaded and one that is meant to open and resave the image with new dimensions [for cropping]).

        protected void btnCrop_Click(object sender, EventArgs e)
            string profilePicFilePath = Server.MapPath("~/AppWide/User/Profile_Pics/" + userForPage.ProfilePicFilePath + "_temp" + ".jpg");

            //1) Load up image into memory
            Bitmap tempImage = new Bitmap(profilePicFilePath);

            Rectangle r = new Rectangle(Int32.Parse(x.Value), Int32.Parse(y.Value), Int32.Parse(w.Value), Int32.Parse(h.Value));

            System.Drawing.Image permImageToSave = cropImage(tempImage, r);

            //2) Resize image in memory using co-ordinates from boxes

            permImageToSave.Save(profilePicFilePath, ImageFormat.Jpeg);

            //3) Save the new image over the top of the old image

        //only allows uploading of .bmp, .jpg and .gif
        protected void ccMediaUploader_FileUploaded(object sender, UploaderEventArgs args)

            //first get th

View Complete Post

More Related Resource Links

SmtpClient and Locked File Attachments

Got a note a couple of days ago from a client using one of my generic routines that wraps SmtpClient. Apparently whenever a file has been attached to a message and emailed with SmtpClient the file remains locked after the message has been sent. Oddly this particular issue hasn't cropped up before for me although these routines are in use in a number of applications I've built.

how to make a css style background image be linked to an image in the resource file


hey guy, i need help in a very troubling matter. I want to make a textbox with a specific style, within this style a set of images as background parts, how can i attach these images to the custom control as whenever i take the .dll file and add it to the toolbar the images do not appear. So i tried to make them as resource files and their property as embedded in .resx file, so how to make the css style background image url to be linked to any of those image.

thanks in advance

Image file does not want to overwrite.


 I am having an issue with saving an image file to a temp file on the server after it is cropped.  I upload the image on one page and then modify it on another with the option to rotate or crop.  I have the crop feature set as a fixed size and am using JavaScript to accomplish this.  I am getting an error when I try to save the file as the original file name to overwrite it with the modified image file.  I know this has got to be something simple that I am overlooking, but I have been looking at it for a while and can't seem to spot the problem.  I currently have the image saved as "studentid_temp.jpg" in the temp folder.  I want to overwrite this file with the new cropped version of the photo.  Below is the code that i'm using, which gives me the error: A generic error occurred in GDI+.

When I change the file ending to something different (like studentid_temp1.jpg) the new cropped image saves without a problem because it does not have to overwrite the original. 

I have set the permissions on the folder to allow read/write functionality.

Any ideas to easily accomplish this overwrite?  I thought overwrite was kind of the default when a file came across with the same name, or is it because I still have the image open from the display (how would I fix that, if that's

Insert image into Infopath form and save to SharePoint as PDF file


I have an InfoPath web-enabled form in MOSS 2007, that is integrated with a K2 blackpoint process for an approval workflow.

Once the form (a Purchase Order request form) has been approved in the K2 workflow process, I switch the form view to a "print-friendly" view for the requestor to view from the browser.  However, now I need to go one step further with this scenario:

1) I need to somehow insert/embed an image with the scanned-in signature of the approver (likely stored in a SP doc library) at the signature line section of my form.  Also, what are the security requirements for storing such images, but not granting all users access to these (e.g. only services accounts that need to access this for embedding into the form, etc.)?

2) Then I need to convert this final "print-friendly" view of the form (with the signature image) to a PDF document so that I can store it in SharePoint (and email it to the requestor using K2's email event capabilities).

Can anyone help me with a solution to both of these requirement, or point me to some resources for this (even 3rd party components are open-game).



Saving Image File in a Folder on Sever from Client Machine using Sql Server

  Hi EveryOne... Can anyone help me Saving an Image file in a Server folder from a client machine using Sql server 2005....   

How to delete an image file assigned to a PictureBox xontrol ?

In a Windows form application, some image files are assigned to PictureBox controls. I am trying to delete those image files. The first approach [1] with "Image.FromFile" gives an error message of "Another process is using this image file", although "Image.Dispose()" is executed. The second approach [2] using "Image.FromStream" results (X) images for PictureBoxes and Buttons, if "fs.Close()" is inclided. Without "fs.Close()", it gives the same error message of "Another process is using...". How can I display images properly and delete those images files ? Thanks [1] pictureBoxSelected.Image = Image.FromFile(@actualImage); . . . pictureBoxSelected.Image.Dispose(); pictureBoxSelected.Image = Image.FromFile(@tempImage);                                                if (System.IO.File.Exists(actualImage) == true) {     System.IO.File.Delete(actualImage); } [2] FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); pictureBox.Image = System.Drawing.Image.FromStream(fs); fs.Close();

WPF: can we reference a image file (~.png or ~.bmp) from a separated assembly?

We try to reference a image file (xxx.png) in a separated Reference assembly call "ResourceLibrary.dllwe have implement following code in another assembly (not main execuation assembly). <Button > <Image x:Name="pageUpArrow" Stretch="Uniform" Source="pack://application:,,,/ResourcesLibrary;component/Images/xxx.png" /> </Button> We get a complaint at run time:Message="Cannot convert string 'pack://application:,,,/ResourcesLibrary;component/Images/xxx.png' in attribute 'Source' to object of type 'System.Windows.Media.ImageSource'. Cannot locate resource 'images/xxx.png'.  Error at object 'System.Windows.Controls.ControlTemplate' in markup file ...Could we directly reference a image file (xxx.png) in saperated assembly?thanks!Jane

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?

How to Set default file name of image in FileUpload Control

helloi want to set  default value in Fileupload control.Because when i select file name using fileupload then save that file to sqlserver database i got problem when no file is select. so i found alternate of that i should store default image into database through fileupload control but now my query is how to set default image to fileupload control.please i want source code.i really need it......tnx in advance

Accessing image file in local machine from server

 Hi i have a  .JPG file in my local machine which has  to be sent as body of SMTP mail. Path of image D://foldername//imagename.jpg The code I run is in the server m\c. I want it to access my local machine's d:\ folder to get the image file. But it is accessing the server m\c's d:\ folder. How can this be done? Thanks Amuda.RG  

attach image/picture to rtf file

RtfTreeNode root = tree.RootNode; FaxOrderForm.AddFont(ref root); RtfTreeNode node = new RtfTreeNode(); RtfNodeCollection bkmk = root.SelectNodes("bkmkstart"); for (int i = 0; i < bkmk.Count; i++) { RtfTreeNode bkmkNode = bkmk[i].ParentNode; if (bkmkNode.PreviousSibling == null) bkmkNode = bkmkNode.ParentNode.PreviousSibling; else bkmkNode = bkmkNode.PreviousSibling; switch (bkmk[i].NextSibling.NodeKey) { case "AAA": bkmkNode.AppendChild(BuildGroupText(textboxA.Text.Trim())); break; } public static RtfTreeNode BuildGroupText(string str) { RtfTreeNode nodeGroup = new RtfTreeNode(RtfNodeType.Group); nodeGroup.AppendChild(new RtfTreeNode(RtfNodeType.Untouched, str, false, 0)); return nodeGroup; } I am now using RTFTreeNode to attach string to rtf file according to the remark name in rtf file but now i don't know how to attach a image/picture to rtf file (i have img file in the program folder that mean i can get the image by passing path) any example code for me c#

Client image files uploaded to Server are staying locked when accessed again.


I have a web form that, upon user request, uploads an image file from the client to a server folder, makes a thumbnail and saves to another folder than sets an imageurl of an image control to that thumbnail. All fine up to here, problem is that at times (not always but could not find the exact pattern) when uploading an existing file, it throws a ' ... file used by another process ... ' error, both on the original image file and the created thumbnail. Is there a way to prevent the locking of these files or alternately, which object need I destroy to release the image file and avoid these contentions? I do destroy the image object immediately after thumbnail is created. Ideas anyone?

Dispaly image from Ms access database to rdlc file


hi all,

    I have done website using Ms access database and VS2005. actually i store image in system.byte[] format in MS access database..so i want to set that image in rdlc background or image tag.

actually  i did the following way..

  OdbcCommand commad = new OdbcCommand("Select img_stream from Key", con);
               OdbcDataReader dr1 = commad.ExecuteReader();

                OdbcDataAdapter myAdapter = new OdbcDataAdapter(commad);
                DataSet myDataSet = new DataSet();
                byte[] imageContent = null;
                foreach (DataRow dRow in myDataSet.Tables["Key"].Rows)
                    if (dRow["img_stream"] != DBNull.Value)

                       imageContent = (byte[])dRow["img_stream"];

                    byte[] imageContent1 = (byte[])((dRow["img_stream"]));


  this.reportViewer1.LocalReport.ReportEmbeddedResource = "Taegutec.Report2.rdlc";
this.reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1_Key", myAdapter));

but i got following Exception

ex = {"Value does not fall within the expected ra

Initialize background image url in css file into custom server controls



i registered an image in AssemblyInfo.cs like this:

[assembly: WebResource("MyControl.Icons.bold.png", "image/png")]


protected override void RenderContents(HtmlTextWriter output)
            output.Write("<p class='BoldButtons' onclick='event4()'>event4 </p>");

now i want to initialize that image in css file for background-image but it dose'nt work.

my css file is:

	background-image: url("MyControl.Icons/font_bold.png");
	border: 0px; 
	height: 21px; 
	width: 21px;

i also try with this :

background-image: url(<%=WebResource("MyControl.Icons.bold.png")%>);

but it dose'nt work.

please help me? 

Impossible to download .sdf file. Locked ?



I have installed a tiny test site derived from template LinkDirectory. It is working fine online, but I just cannot download the .sdf file.

When I try, using Filezilla, here is what I get :

Commande : RETR LinkDirectory.sdf
Réponse : 550 The process cannot access the file because it is being used by another process.

Commande : RETR LinkDirectory.sdf

Réponse : 550 The process cannot access the file because it is being used by another process.

How can I unlock this situation.

Thanks in advance.


C# Tutorial - Image Editing: Saving, Cropping, and Resizing

In C# it can be tiresome to do certain image editing functions using GDI+. This post has some fun editing methods which can come in handy at times. I have also included a nice little C# program to show all the functionality of the methods below.

Saving a Jpeg
The first thing to do here is set up the method signature with the input parameters. These are the save file path (string), the Image to save (System.Drawing.Bitmap), and a quality setting (long).

WCF: Read file system image and return image thru wcf



I have a service which reads an image stored in the database. I want to be able to read an image stored on the file system and return that back to the requestor, is that possible?

Thanks for your help! :)


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