|
Hi,
1. there are a couple of ways to keep a file "in use by another process", and you should, for once, not take "another process" literally. Here are some:
- another process has opened the very same file
- for text files that other process could be an automatic indexer
- for several extensions that other process could be an antivirus checking a newly created file
- MOST LIKELY IN YOUR CASE: an image loaded with Image.FromFile() remains locked as long as the image lives.
2. numeric format "D3" would always use at least 3 characters, filling with leading zeroes.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
Check if the "image" file you want to move is already opened from somewhere else.
The second problem is :
See this line :
this.Text = string.Format("{0:00}", 12);
it has to be
this.Text += string.Format("{0:00}", 12);
|
|
|
|
|
I think your missing the point of the question. I believe the OP was trying to demonstrate that the number formatting did not include the desired prefix of zeros.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
The error usually occurs when you have a reference to the image still active. How are you loading the 'images' list can you show the code for that please.
with regards to the fomatting then try using the int.ToString() method...
int i = 12;
string s = i.ToString("000");
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
In addition to Luc's points, for 2.
public F_Main()
{
InitializeComponent();
files = Directory.GetFiles(dir);
this.Text = string.Format("{0:D3} - {1:D3} - {2:D3}", 1, 12, 120);
}
seems neater and easier to read to me.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry Minute wrote: this.Text = string.Format("{0:D3} - {1:D3} - {2:D3}", 1, 12, 120);
Problem with that is it will only work for a fixed number of files, which anything above 1 seems like too much work for me
...Thou given the OP's example it would produce what he was showing. My assumption is that each file with be appended with a number that increments with each file
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
musefan wrote: it will only work for a fixed number of files,
Whilst that is true, I was simply implementing the users own logic, in what I thought was a better way. You are absolutely correct if there were likely to be an unknown number of files.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
that's why I edited my post as I can see you are just providing a solution based on the OP's example
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Thanks.
For the formatting "D3" works the way I want.
Though, the main problem is still the renaming.
I changed the code for displaying the picture to:
Bitmap picture = new Bitmap(800, 600);
picture = new Bitmap(images[0]);
PB_Image.Image = new Bitmap(picture);
picture.Dispose();
TB_Old_Name.Text = Path.GetFileNameWithoutExtension(images[0]); And this is the code I use for renaming:
L_Status.Text = "";
File.Move(Path.GetFullPath(images[current]), Path.GetFullPath(TB_New_Name.Text));
L_Status.Text = "image '" + images[current] + "." + extension + "'\r\nhas been renamed to\r\n'"
+TB_New_Name.Text + "." + extension + "'";
images[current] = TB_New_Name.Text; But now the program simply deletes the image.
I tested it and the image that should have been renamed simply disappeared.
|
|
|
|
|
Good day to all off the codeproject members.
is there anyone who has some sample c# code that can read from a mifare rfid reader (through a serial comm port)
It is a PCR310 RFID reader with GNET plus protocol
With kind regards
Gerrit
|
|
|
|
|
All of the stuff I see on this, from a quick search, says that it comes with a software module, do you not have that?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thx Henry,
You were right i recieved the packadge from the dealer. after a call
Working on it now.
with regards,
|
|
|
|
|
Hi GerritdL,
Any success with the C# program. I am stuck with PCR310U and not able to get UID.
Regards,
|
|
|
|
|
Hello there,
I am programming C# using MS Visual Studio Professional Edition 2008 and MS Office Excel 2007.
My Problem is that I want to mark a range, copy and insert it at the same position shifting existing cells down. I can do this with the Excel GUI - no problem. But programmatically I get a System.Runtime.InteropServices.COMException, telling me that the Insert-method of the Range-object could not be executed (German text:"Die Insert Methode des Range-Objektes konnte nicht ausgeführt werden.").
The range I want to copy has got some special formats (font, color, some merged cells), and I need these for each entry I have to insert.
I am trying this code
<pre>
Excel.Worksheet sheet = (Excel.Worksheet)wb.Sheets["mySheet"]; // wb is the actual workbook
Excel.Range range = sheet.get_Range(sheet.Cells[16, 1], sheet.Cells[18, 37]);// this is "A16:AK18"
range.Insert(Excel.XlInsertShiftDirection.xlShiftDown, range);
</pre>
Here come the questions:
Why can I not insert the range? What are possible reasons?
How can I insert the desired range?
Thanks in anticipation!
Harry
no plan,
no signature
|
|
|
|
|
Harry666 wrote: Excel.Range range = sheet.get_Range(sheet.Cells[16, 1], sheet.Cells[18, 37]);// this is "A16:AK18"
you can directly use like this:
Excel.Range range = sheet.get_Range("A" +16, "AK" +18);// this is "A16:AK18"
|
|
|
|
|
Is it good for any purpose to use the letters instead of numbers,
besides getting the range out of a string instead of the Cells[] Array?
I'm asking, because I have to count and calculate with the rows - well, not the columns...
I want to say: in both cases I use the get_Range()-method. Is there any difference in the range which I get using another param?
Harry
no plan,
no signature
|
|
|
|
|
I think you have to select the range first. so, before the range.Insert try and insert the following statement to selct the range that you just specified range.Select() . Hope this helps, if not let us know.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
I just tested the below code using VS2005 and it works fine.
objRange = objSheet.get_Range("A16", "AK18");
objRange.Select();
objRange.Insert(XlInsertShiftDirection.xlShiftDown, objRange);
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Thanks for the reply!
Yes, I tried to select my range. Actually, I did select it, but the insert still throws that Exception.
Btw: I read an article (Sorry, I forgot where that was), where the author wrote and explained why You do not need to select (or activate) a range and tell the program what to do with "ActualRange"... instead of
myRange.Select()
ActualRange.doSomething()
it would be the same (even shorter) to do like this:
myRange.doSomething()
Again, it is not the Select() that misses. I think that it's got s.th. to do with protection and rights or so.
Harry
no plan,
no signature
|
|
|
|
|
Partial success...
I've got several worksheets in my workbook. In some of them I have to do this: mark, copy and insert a special range of the sheet into the same sheet.
I tried to...
Excel.Worksheet sheetKL = (Excel.Worksheet)myWorkbook.Sheets["KL"];
Excel.Range range = ((Excel.Range)sheetKL.Cells[10, 1]).EntireRow;
range.Select();
and the Select-method throws an Exception
after this I tried to...
Excel.Worksheet sheetKL = (Excel.Worksheet)myWorkbook.Sheets["KL"];
sheetKL.Select(true); //select the sheet
Excel.Range range = ((Excel.Range)sheetKL.Cells[10, 1]).EntireRow; //create the range
range.Select(); //select the range
range.Insert(Excel.XlInsertShiftDirection.xlShiftDown, range);
but then, still, the Insert-method throws the Exception.
Harry
no plan,
no signature
|
|
|
|
|
Sorry about that Harry. I am home in bed now and will definately look into this in the morning. I have had a tough time with Excel when I wrote my first Excel app but got it to work just fine. I'll see what I can do with it and post back.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
|
Here you go mate. Excel programming is a major pain. Believe you me. Below the code that you want to use. The Origin is what is missing. The best way of getting things in perspective is to write a MACRO in Excel and check the code behind it. That should always give you a good idea of what you need to do.
objRange = objSheet.get_Range("A6", "AK8");
objRange.Select();
objRange.Insert(XlInsertShiftDirection.xlShiftDown, XlInsertFormatOrigin.xlFormatFromLeftOrAbove);
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
|
Here I am again,
trying to copy and insert my excel-cells...
Well, what I want to copy is the style, the fonts, size, colors, the way they are merged, borders (boxes) around them, and so on. I do NOT need the content of these rows, I DO need the shape, format and so on.
Using the GUI, the Excel Application itself, I mark the row (with the mouse), copy and paste (or insert) it.
For this reason I think, doing so must be correct:
Excel.Range range = mySheet.getRange(("A"+10, "Z"+10)).EntireRow; //grab the line
range.Insert(Excel.XlInsertShiftDirection.xlShiftDown, Excel.XlInsertFormatOrigin.xlFormatFromLeftOrAbove); //copy and paste (-> insert)
or afaik even ...
Excel.Range range2 = mySheet.getRange(("A"+11, "Z"+11)).EntireRow; //mark the next line
range.Copy(range2); //instead of insert
... should do almost the same.
In fact, no. It does not. It's only copying the cell's contents (or sometimes the color... )
So, is there anything else to care about, when I do not need the contents of the cells but rather their lookalikes (like font, color, cellheight,width,...)?
...And what is it?
Thanks in anticipation
Harry
no plan,
no signature
|
|
|
|