|
|
Hi,
all files are binary, some contain text (in ASCII, Unicode, whatever), some
contain an image, or some other kind of data.
So you might have to clarify your question.
|
|
|
|
|
Of course, all files are Binary, but i want to differentiate files based on the printable characters they contain. Basically, i need it for a utility which would compare two files and write the differences between them to third file, or may update one file by comparing it to the others. I can only tell this much. Since, such comparision for "binary" files like DLL, Jar etc are meaningless i wanted to identify them before i compare them. I can't change the utility i will use for such comparision. I wrote following method, which i think would work fine. Do you think it would work across all character sets? I am just reading file byte by byte and looking for a byte which is zero. Then i know that the file is binary.
static bool isBinary(ref BinaryReader binaryReader) {
bool nullByteFound = false;
int i = 0;
byte unsignedByte;
while (i < binaryReader.BaseStream.Length) {
unsignedByte = binaryReader.ReadByte();
if (unsignedByte == 0){
nullByteFound = true;
break;
}
i++;
}
Console.WriteLine("Bull= " + nullByteFound);
return nullByteFound;
}
The other API IsTextUnicode may also help in solving problem if i retrieve IS_TEXT_UNICODE_NULL_BYTES flag. Thanks all for your help on this.
|
|
|
|
|
Hi,
if a text file is encoded using ASCII or ANSI or some other 8-bit character set,
then zero-testing looks acceptable.
if a text file is encoded using some 16-bit encoding scheme, then zero bytes
can occur in text files (e.g. the char 0x0100, 0x0200, etc).
You could check the first few bytes of the file, Unicode/UTF8/UTF16 use special
values here; if these match you might assume it is text and skip further
testing (and once in a while such assumption will be wrong);
if they dont match you could assume it is an 8-bit encoding, and do the zero test.
Whatever you do, since 100% confidence will not be achievable, I see no point
in checking more than a few hundred bytes before deciding text/no text.
|
|
|
|
|
I am doing a Project that is in ASP.NET 2.0 and C# with SQL Server 2000 on Windows XP.
through Programming I am creating a PDF document and inserting some values into that.After that I am sending this PDF doc in mail attachment to some mail ID.
initially PDF was corrupting and one page was corrupt.(Error was cooming :An error exists on this page.Acrobat may not display the page correctly.Please
contact the person who cretaed the PDF document to correct the problem.)
Then I used UUEncoding then Mail attchment was comming properly to other mail accounts like yahoo etc.but it was cooming to gmail account in plain text format instead of attchment.
what's wrong I am doing???
What is the solution for that??Plz help me in this regard as soon as possible.
you can mail me at adil@vsoftconsulting.com
adil kazmi
|
|
|
|
|
It would have been better for you to delete the post without a response to it already.
|
|
|
|
|
Hmm,
At first it was just a decision between one of the two post.
Which can of course be a hard decision.
Because they where all the same, and maybe the one which is going to be choosen, will be angry afterwards.
Than somebody made it clear by answering one of the posts.
So decision was not too far away.
But than in the last second totally confusion by exactly the same post which should make it clear first.
"Please delete one of your posts"
I'm not sure if I would have choosen the correct one in this situation
|
|
|
|
|
Hi all
Can anybody tell me how to create a dockable toolbar in C#. I neet it very urgently. Please help me.
Regards
Sagar Pattnayak
Sun-Dew Solutions
9831169962
|
|
|
|
|
|
Is it possible to have a single handler for all the context menu items.
In fact I know that all clicks to a context menu can be captured by the event "ContextMenu_Click"
But how do we know which menu item was clicked?
Thanks in advance
Deepu
|
|
|
|
|
Deepu AM wrote: how do we know which menu item was clicked?
by examining the sender parameter
|
|
|
|
|
Thank you for your reply Giorgi.
But the only options available for "sender" parameter are
Sender.Equals()
Sender.GetHashCode()
Sender.GetType() &
Sender.String()
I cant figure out how to get the menu item which was clicked using these methods.
Please help.
Thanks
deepu
|
|
|
|
|
You should cast the sender to the appropriate type.
|
|
|
|
|
Thank you for helping Giorgi
|
|
|
|
|
Hello,
You have to cast the sender to an instance of "System.Windows.Forms.MenuItem".
This can be correctly done with the as operator!
System.Windows.Forms.MenuItem clickedMenuItem = sender as System.Windows.Forms.MenuItem;
if(clickedMenuItem !=null)
{
// clickedMenuItem.Text
}
Hope it helps!
All the best,
Martin
|
|
|
|
|
|
|
A newbie question. I'm walking through a C# workbook which illustrates how to create constructors for classes and class hierarchies. Now when the code is creating a new instance of a derived class the first keyword denotes an abstract class:
GenericCustomer customer = new Nevermore60Customer("Arabel Jones");
What does GenericCustomer (abstract class) refer to, since we are creating an instance of Nevermore60Customer (derived class from GenericCustomer)?
Jon
Code:
using System;
namespace TestmyJesus
{
/// <summary>
/// Summary description for Class1.
/// </summary>
///
abstract class GenericCustomer
{
private string name;
public GenericCustomer(string name)
{this.name = name;}
}
class Nevermore60Customer : GenericCustomer
{
public Nevermore60Customer(string name, string referrerName)
: base(name)
{ this.referrerName = referrerName;}
public Nevermore60Customer(string name): this(name, "<None>")
{}
private string referrerName;
private uint highCostMinutesUsed;
}
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
GenericCustomer customer = new Nevermore60Customer("Arabel Jones");
// What does GenericCustomer refer to, since we are creating an instance of Nevermore60Customer? }
}
}
Jon
|
|
|
|
|
|
How does this relate to my question?
Jon
|
|
|
|
|
jon_80 wrote: How does this relate to my question?
This question arose because you need further, deeper reading about polymorphism.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Thanks for reading my mind, but I wasn't actually after a tutorial
Jon
|
|
|
|
|
Oh, and where were you actually?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
following through a c# tutorial...
Jon
|
|
|
|
|
Sorry, I misunderstood what you wrote. I perceived it as ironic. Sorry again
Losely speaking, when you use:
GenericCustomer customer = new Nevermore60Customer("Arabel Jones");
you are creating a fully featured class Nevermore60Customer instance. However you can pass it to any method expecting a GenericCustomer as argument (the method hasn't even to know about Nevermore60Customer class esistence!).
On the other hand, the customer instance will act polymorphically, i.e. each method called on it will have the behaviour defined Nevermore60Customer .
Polymorphism is a rather complex concept and I gave a very poor hint to you. But that's
life.
(Anyway there are a lot of good examples on teh topic, you have only to use Google)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|