|
Sorry, I don't see anything wrong with the code. I was able to run it without any problems, other than to remove the if (len==6) statement so I could test it.
Do you get this error everytime the code runs or just with certain input?
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
This is with any date value that I type and happens every time.
I have the same issue even after removing if (len ==6) statement.
Thanks,Arun
|
|
|
|
|
I got it. My mistake was to try using the date "121203" and trying to use the
DateTime.ParseExact(txtEffDt.Text, "MM/dd/yyyy", null) instead of DateTime.ParseExact(txtEffDt.Text, "MMddyy", null).
Thanks all for the help.
Thanks,Arun
|
|
|
|
|
No problem. Glad you were able to figure out what was going on. If you know you will only be accepting a limited number of input formats you can pass a string array to the DateTime.ParseExact method and it will try to match against any of the formats in the array.
You also might want to look at the DateTime.TryParseExact method as well. The benefit to this is that it doesn't throw the exception and returns a bool value that indicates if the parse passed. The new date is returned as an out parameter.
-----------------------------
In just two days, tomorrow will be yesterday.
|
|
|
|
|
i want to start a video in a powerpoint slide how can i do?
i tried sending mouse click into the video, however it is not working (
mouse_event, sendinput, sendmessage, peekmessage... all of these functions don't work to send click into video
Please write what ever you know to solve my problem
|
|
|
|
|
i want to draw 25 circle shapes in my form
5 circle per row in 5 columns
and these circles have event on_click
ma_refay
|
|
|
|
|
There are round button classes on CP.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum ) tHERE
|
|
|
|
|
Hi,
I tried to develop a windows service in C#.Net 2.0 to move files from a directory to another directory but my problem is this, when the file is uploaded that directory, event firs up, even the file is not completely uploaded, and it gives me error, as file is still uploading, is there any way to solve this problem other than while loop to check that file is completed uploaded and is acceable now, please suggest.
Many Thanks,
Adnan Rafiq
muhammadadnanrafiq@gmail.com
|
|
|
|
|
Hi Adnan,
Are you using a FileSystemWatcher to monitor the upload directory?
If so, you have to make a do/while loop and try do access the file in a try/catch block inside the do/while loop. If you can access the file (it doesn't throw an exception of being current in use) you set a flag in order to exit from the loop. I think it should look something like this:
<br />
bool uploadCompleted = false;<br />
do<br />
{<br />
try<br />
{<br />
File.Open("yourFileName", FileMode.Open, FileAccess.Read).Close();<br />
uploadCompleted = true;<br />
}<br />
catch<br />
{<br />
}<br />
}<br />
while (uploadCompleted != true)<br />
I done it before and it worked. I couldn't find another approach so solve it (even made some posts in CP to find an answer). The problem is that the event is fired up even when the copy/move/creation is not complete, so you can't access the file yet. :/
Someone developed a customized code do solve this and wrote an article about this wrapper here in CP, but I thought it was too complicated and done the almost same thing I'm saying after all.
Hope it helps you...
CYA
|
|
|
|
|
Hi, Thanks for replying and understanding problem
Please tell me one thing, if i implement this solution of do while loop, and the uploading directory is getting files every second what will happen in that case, i think its performance will be stuck out, as other thread have to wait to finish out the while loop, or i mean wt will happened in that case. using filesystemwatcher the only .net component available to watch a directory..............
Please i hope you will understand what i m trying to say.
Many Thanks,
Adnan Rafiq
muhammadadnanrafiq@gmail.com
|
|
|
|
|
Sure, performance in this case will be stuck.
I think you can do a Thread.Sleep() inside the do loop, like 500ms. It should help a little. I don`t know another aproach.
Hope someone help you more than I did. :]
Cheers
|
|
|
|
|
Hello,
I would like to display small window with web page inside window of antoher web page.
is it possible? how to do this using HTML?
Thanks!
cyberjoe
|
|
|
|
|
|
|
Hello,
I'm new to programming and C#, so please bear with my ignorance!
I need to extract jpeg images and header data from a binary file.
The binary file is formatted with several fixed length fields containing information about the jpeg image, followed by the jpeg itself, followed by more header data, another jpeg, etc...
Using a FileStream and BinaryReader I am able to read and store the metadata, because I know the length of the fields, but I am stumped on how to read and store the jpeg bytes since they vary in size.
There is a fixed record delimiter between each header data/jpeg record, so I was thinking of using that to break apart the records. Once they are seperated and the header fields read, I could just assume the rest is the jpeg and store that. I'm not sure how to go about doing that though.
Any suggestions or demo code is greatly appreciated!
Thanks!
|
|
|
|
|
Hi,
assuming you are in control of the file format, this is what I suggest:
prefix each record with a byte indicating the record type, and terminate the file with
yet another record type (I suggest a zero byte here). So a file would look like this:
type0 record0 type1 record1 type2 record2 ... typeN recordN 0
Now each record could correspond to a C# struct, and that struct could contain
a Save(stream) method to append the struct as a record to the file stream (dont forget
the type byte!), and a Load(stream) method to create and populate a struct by reading
from the file stream (starting after the type byte).
Now loading the file stream would consist of a loop containing
- read the byte that tells the record type
- use a switch to call the right struct's Load method
- if end-code, close stream
If you cant follow the above scheme (e.g. because the file format has been fixed
and does not include a type byte), then you need to determine the type of the next record
by reading and analyzing some bytes, then rewind a bit (using
Seek method or Position property) and Load a record; repeat until done.
Hope this helps.
|
|
|
|
|
Thanks for the suggestions! Unfortunately, I am receiving this binary file from a third party and it's format is out of my control.
The fields in the records seem to be seperated by a zero byte, and the records are seperated by a 16 byte string. Also, I noticed that the jpeg data starts with the bytes (in HEX) FF, D8, FF, E0 and ends with FF, D9. Could I possibly use these byte sequences to identify the jpeg?
Also, I'm very new to this so all I have figured out how to do so far in code is to read my fixed length fields like so:
FileStream fs = File.OpenRead(strFileName);
BinaryReader reader = new BinaryReader(fs);
//reads the first 36 bytes of trash
reader.ReadBytes(36);
//reads and stores the record delimiter string
string strSignature = Encoding.ASCII.GetString(byteSignature);
//advances the curser 1 byte
reader.ReadBytes(1);
//stores SKS ID
string strSKSID = Encoding.ASCII.GetString(reader.ReadBytes(16));
//advances the curser 1 byte
etc... reading down until I get to the image field.
Luc Pattyn wrote: If you cant follow the above scheme (e.g. because the file format has been fixed
and does not include a type byte), then you need to determine the type of the next record
by reading and analyzing some bytes, then rewind a bit (using
Seek method or Position property) and Load a record; repeat until done.
I'm not sure how to actually implement your suggestion of reading and analyzing some bytes, then rewinding. Could you provide some example code?
Thanks again!
|
|
|
|
|
Hi,
since you dont control the file format, here are the fundamentals you will need, plus
some suggestions:
- use one FileStream for your file
- use BinaryReader.ReadBytes() to read a number of bytes at the current position (it will
advance the current position); problem here is you must specify the byte count
- create a number of classes or structs, one for each possible record type.
- if class/struct RecordType1 is one of the possible record types, you should give it
two static methods:
bool Accept(FileStream) would read some bytes and decide whether or not the data fits the
record type for that class/struct; it should restore the filestream position as if
nothing happened (use FileStream.Position property to remember where you are in the file,
and to return to that position); it should not throw exceptions to the caller.
RecordType1 Load(FileStream) would read all the bytes needed to load a record of that type,
knowing it is of that type (since it will have been Accepted beforehand). Load does
advance the filestream, so it consumes the record and returns the result. It should throw
exceptions when something fails.
- details on Accept: you can try and recognize the first few bytes; JPEG always start
with FF D8 and often with FF D8 FF E0; but nothing prevents other (non JPEG) records
to also start with FF D8 !! So your collection of Accept() methods should be sufficiently
accurate to discern the record types at hand.
- details on Load: you should know the byte count in order to read the right number
of bytes; scanning for an end marker is difficult: even if JPEG always ends on FF D9,
that does not mean the first FF D9 is the end of a JPEG (it could be a bit pattern
in the middle of the pixel info).
- it is rather hard to decode JPEG, so I suggest to let GDI+ try and decode a JPEG image.
One way would be to create a memory stream from your byte array, then call
Image.FromStream(MemoryStream), but I suspect you could directly call
Image.FromStream(FileStream) avoiding the byte count problem completely.
- you can create a new BinaryReader in every Accept and every Load method in each
RecordType class/struct, or reuse a single one all over the place (dont try something
intermediate).
- also provide a class/struct to handle the end-of-file record; it needs an Accept
but does not need a Load() method.
- and now the finale: put all your Accept and Load methods in one loop to decode the
entire file, as in:
try {
FileStream fs=...
for ( ; ; ) {
bool accepted=false;
if (RecordType1.Accept(fs)) {
accepted=true;
RecordType1 rec1=RecordType1.Load(fs);
...do whatever needs to be done with rec1
continue;
}
if (RecordType2.Accept(fs)) {
accepted=true;
RecordType2 rec2=RecordType2.Load(fs);
...do whatever needs to be done with rec2
continue;
}
...etc
if (RecordTypeN.Accept(fs)) {
...this one recognizes end of file
...close the shared BinaryReader if there is one, close the FileStream
break;
}
if (!accepted) throw new ApplicationException("Cant recognize record...");
}
} catch(Exception exc) {
... handle the exception
}
- the order of the RecordType# blocks may be relevant, since the first one that
returns a true on Accept will (have to) consume the data, so put the most strict
acceptors first.
Basically thats it, the rest are details...
|
|
|
|
|
Well, I was finally able to do this in a pretty efficient way.
I just read in the entire file, about 256k, to a byte array. Then I could convert it to a string in order to use string.IndexOf to find the record delimiters. I then used those demlimiter positions and Array.Copy to copy what I wanted out of the original byte[] to it's own byte[]. From there it was easy to get the image because each record has a fixed 223 byte header, so the remainder of the record had to be the embedded image. I just copied what was left of the record after the first 223 bytes to another byte[] and wrote it to disk, named it .jpg, and tada, I had the jpeg image!
|
|
|
|
|
Hi, I'm glad you got something working.
I would not fully trust the string.IndexOf part, since string operations
perform unpredictably on non-string data (such as JPEG images, which can
contain any bit pattern, that could be misinterpreted as Unicode characters).
htres wrote: each record has a fixed 223 byte header
That's new info, makes things easier I guess.
htres wrote: wrote it to disk, named it .jpg, and tada, I had the jpeg image
As I mentioned earlier if you want the image I guess you can do it without
such file using Image.FromStream(); if you need the file, then it is the
way to go.
|
|
|
|
|
Luc Pattyn wrote: I would not fully trust the string.IndexOf part, since string operations
perform unpredictably on non-string data (such as JPEG images, which can
contain any bit pattern, that could be misinterpreted as Unicode characters).
You are right, I had a lot of trouble with string.IndexOf when I was trying to isolate just the jpeg by searching for small strings of 2-4 chars. But after a lot of testing using it to find the record delimiter, which is the same 16 byte string in every record, it works very reliably. Even though it is entirely possible for this particular 16 byte string to show up within the jpeg encoding, the odds are against it.
Luc Pattyn wrote: htres wrote:
each record has a fixed 223 byte header
That's new info, makes things easier I guess.
Yeah it was a lot easier. That 223 byte header contained the fixed length fields that held the information about the image. I probably should have posted an example of the file format...but it would have been ugly since it is mostly binary.
Luc Pattyn wrote: htres wrote:
wrote it to disk, named it .jpg, and tada, I had the jpeg image
As I mentioned earlier if you want the image I guess you can do it without
such file using Image.FromStream(); if you need the file, then it is the
way to go.
I haven't tried the Image.FromStream option yet, though I plan to eventually. Ultimately I'd like to populate a database with the picture and header data as well. But I'll leave that part for a new thread...
Thanks for the help!
|
|
|
|
|
If you have control over the binary file format, this may help. Make sure that one of the attributes in the fixed length header is the length of the following JPEG image data. You could then create a byte array (byte[]) of the length of the JPEG image and read the specified number of bytes to the byte array using:
BinaryReader.Read(byte[], int index, int length)
|
|
|
|
|
I'm working on a custom control that extends DataGridView.
It has a Form as its custom property editor, like property pages we had in VB6.
The property editor is simply another form popped up when a designer verb of the control is selected.
This form contains the interface required to specify the columns to be added to the parent datagridview instance.
When I use the costom datagridview control in a form and specify some columns to it, they are visible in design time, this is what i was upto. The problem is that every time I edit the grid instance throught the custom property editor a new set of columns are added into froms source. However, the previous ones are detouched from the grid but remain in the code page, cluttering up the source.
I would vastly appreciate help/suggestion in accomplishing two things,
1. Being able to Programatically specify the names of the columns (e.g. PersonName_col, insted of the default dataGridViewTextBoxColumn1...)
2. if the above is no allowed, a process of cleaning up the recedue (detached from the grid) columns from the forms source.
I'd be obliged to salute anybody who can understand what I'm trying to say, cause I myself am not very sure if have said it meaningfully enough. Nevertheless this is the place where I've seen many wonders take place.
Gratitude in advance to the kind heart(s) that will even attempt to help me out.
(Its oh so hard for me to keep it short)
Galib Anwar
A C# shortimer.
|
|
|
|
|
Hi...
I`ve done a COM DLL (using C#.NET 2.0) to use in my VB6 app. OK. It worked well in my dev computer where i compiled it and let VS2005 register it for COM Interoperation.
But I need to use this COM DLL in another development enviroment (and further put it in a production enviroment) without VS2005. I`ve tried the regasm utility and intellisense works there in VB6, but I get an error when I try to run my project (Automation Error. The system cannot find the file specified").
Any hint?
Thanks
|
|
|
|
|
I think you either need to add a reference to the dll project, or the path to the dll to your development environment's search path.
|
|
|
|
|