Click here to Skip to main content
15,899,474 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: How does Application.DoEvents work? [modified] Pin
the Kris8-Sep-10 8:29
the Kris8-Sep-10 8:29 
GeneralRe: How does Application.DoEvents work? Pin
Fabio Franco8-Sep-10 8:38
professionalFabio Franco8-Sep-10 8:38 
AnswerRe: How does Application.DoEvents work? Pin
englebart8-Sep-10 8:46
professionalenglebart8-Sep-10 8:46 
AnswerRe: How does Application.DoEvents work? Pin
Scott Barbour8-Sep-10 10:08
Scott Barbour8-Sep-10 10:08 
GeneralRe: How does Application.DoEvents work? Pin
MicroVirus10-Sep-10 12:41
MicroVirus10-Sep-10 12:41 
QuestionCalendarExtender popup appearing when Enter key is pressed Pin
dev_asp_shreshtha6-Sep-10 1:09
dev_asp_shreshtha6-Sep-10 1:09 
AnswerRe: CalendarExtender popup appearing when Enter key is pressed Pin
Pete O'Hanlon6-Sep-10 1:30
mvePete O'Hanlon6-Sep-10 1:30 
QuestionNot able to delete original jpeg file after it is copied with System.IO.File.Copy() Pin
Aseem Sharma5-Sep-10 6:43
Aseem Sharma5-Sep-10 6:43 
Hi all,

I am doing a very simple operation via c#.

1 I just copy an existing JPEG file in temp directory.
2 Then I open the copied Jpeg file from temp directory.
3 I try to delete the original Jpeg file and application crashes.

Please see below c# function for this:


using System.IO;
public void DeleteAfterCopyingOriginalImageFile(string strOriginalJpeg)
{
   // Create "JpegTemp" sub-folder at temporary directory path
   string strTempFolder = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "JpegTemp");
   if (!Directory.Exists(strTempFolder))
   {
      DirectoryInfo directory = Directory.CreateDirectory(strTempFolder);
      directory.Attributes = directory.Attributes | FileAttributes.Hidden;
   }

   // Get the temp file path
   string strTempJpeg = System.IO.Path.Combine(strTempFolder, "TempImage.jpg");

   // Copy the original JPEG as below
   if (!File.Exists(strTempJpeg))
   {
      File.Copy(strOriginalJpeg, strTempJpeg);
   }

   // Open the "TempImage.jpg" file in default viewer. Doing this lock the original jpeg file.
   // Don't know why? It is creating problem for me.
   Process.Start(strTempJpeg);

   // Delete original JPEG file. Since the file is locked in above step, application throws exception
   // "File being used by some other process" and then application crashes.
   File.Delete(strOriginalJpeg);
}


I need to follow exactly these steps (cannot delete original file before opening TempImage.jpg). Can anybody help in knowing why copy and opening of temp file lock the original file. How can I prevent original jpeg file from being locked. I am new in .Net. Please help me.

More Info about the user case: The user case is that user cannot perform any operation on original file. So a temporary copy of original file is created in temp folder. User can then open/edit temp file. And if he thinks that he can replace original file with that of edited (copied in temp directory) one or he does not need original file any more, he can delete original file (and if required, can make temp file as the original one). So I strictly need to follow the same steps.

Regards
Aseem

Thanks in Advance
AnswerCross post/re-post Pin
Not Active5-Sep-10 7:14
mentorNot Active5-Sep-10 7:14 
QuestionLoad image problem Pin
Mehdi Ghiasi3-Sep-10 5:05
Mehdi Ghiasi3-Sep-10 5:05 
AnswerRe: Load image problem Pin
Dave Kreskowiak3-Sep-10 6:29
mveDave Kreskowiak3-Sep-10 6:29 
AnswerRe: Load image problem Pin
Luc Pattyn3-Sep-10 6:48
sitebuilderLuc Pattyn3-Sep-10 6:48 
QuestionRe: Load image problem [modified] Pin
Mehdi Ghiasi3-Sep-10 15:09
Mehdi Ghiasi3-Sep-10 15:09 
AnswerRe: Load image problem Pin
Dave Kreskowiak3-Sep-10 18:17
mveDave Kreskowiak3-Sep-10 18:17 
QuestionHow to deploy an application along with .net framework Pin
NarVish3-Sep-10 2:13
NarVish3-Sep-10 2:13 
AnswerRe: How to deploy an application along with .net framework Pin
Not Active3-Sep-10 2:22
mentorNot Active3-Sep-10 2:22 
GeneralRe: How to deploy an application along with .net framework Pin
NarVish3-Sep-10 3:16
NarVish3-Sep-10 3:16 
GeneralRe: How to deploy an application along with .net framework Pin
Not Active3-Sep-10 4:05
mentorNot Active3-Sep-10 4:05 
GeneralRe: How to deploy an application along with .net framework Pin
NarVish5-Sep-10 19:37
NarVish5-Sep-10 19:37 
AnswerRe: How to deploy an application along with .net framework Pin
RaviRanjanKr21-Dec-10 3:57
professionalRaviRanjanKr21-Dec-10 3:57 
QuestionProperty 'To' is 'ReadOnly'. Pin
DeepshikhaJohar2-Sep-10 20:51
DeepshikhaJohar2-Sep-10 20:51 
AnswerRe: Property 'To' is 'ReadOnly'. Pin
SeMartens2-Sep-10 21:47
SeMartens2-Sep-10 21:47 
AnswerRe: Property 'To' is 'ReadOnly'. Pin
Pete O'Hanlon2-Sep-10 22:57
mvePete O'Hanlon2-Sep-10 22:57 
AnswerRe: Property 'To' is 'ReadOnly'. Pin
Luc Pattyn3-Sep-10 3:11
sitebuilderLuc Pattyn3-Sep-10 3:11 
JokeRe: Property 'To' is 'ReadOnly'. Pin
Not Active3-Sep-10 4:08
mentorNot Active3-Sep-10 4:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.