|
Try it with a known file: Save this page to a temporary file, and replace the c:\XXTemp\Test.bin with that file. Then, change as shown below:
using (FileStream fs = new FileStream(@"C:\XXTemp\CodeProject Reply to Message_ Free source code and programming help.mht", FileMode.Open))
{
if (fs.CanSeek)
{
fs.Seek(0x44, 0);
byte[] buffer = new byte[100];
fs.Read(buffer, 0, 100);
StringBuilder sb = new StringBuilder();
foreach (byte b in buffer)
{
sb.Append((char)b);
}
MessageBox.Show(sb.ToString());
}
}
Note changes in Seek, buffer size and amount read.
When I run this, I get
Reply to Message. Free source code and programming help
Date: Wed, 15 Jul 2009 15:50:47 +0100
MIME
Open your file in Notepad (not by double clicking) and see if what you get in the MessageBox matches the file.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I write the data to the end of file with this code:
public bool AppendToBinary(string File, string strToAppend)
{
FileStream fs = null;
BinaryWriter bw = null;
try { fs = new FileStream(File, FileMode.Open, FileAccess.ReadWrite); }
catch { throw new Exception("Dosya akışı oluşturulurken hata oluştu."); }
try { bw = new BinaryWriter(fs); }
catch { throw new Exception("Binary okuyucu oluşturulurken hata oluştu."); }
try
{
bw.Seek(0, SeekOrigin.End);
bw.Write(strToAppend);
}
catch { throw new Exception("Dosyaya yazılırken hata oluştu."); }
finally { bw.Close(); fs.Close(); fs.Dispose(); }
return true;
}
I get the location of the desired string in file with this code:
public long DigBinary(string File, string strToDig)
{
FileStream fs = null;
try { fs = new FileStream(File, FileMode.Open, FileAccess.Read); }
catch { throw new Exception("Dosya akışı oluşturulamadı."); }
try
{
byte[] icerik = new byte[fs.Length];
fs.Read(icerik, 0, (int)fs.Length);
string asText = Encoding.UTF8.GetString(icerik);
int index = asText.IndexOf(strToDig);
if (index == -1)
return -1;
if (strToDig != asText.Substring(index, strToDig.Length))
return -2;
return index;
}
catch { throw new Exception("Dosya okunurken hata oluştu."); }
finally { fs.Close(); fs.Dispose(); }
}
I try to read data from the desired location of file to the end with this method: But it doesn't work...
public string ReadBinary(string File, long origin)
{
FileStream fs = null;
try { fs = new FileStream(File, FileMode.Open, FileAccess.Read); }
catch { throw new Exception("Dosya akışı oluşturulamadı."); }
StringBuilder sb = new StringBuilder();
try
{
if (fs.CanSeek)
{
fs.Seek(origin, 0);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, (int)fs.Length);
foreach (byte b in buffer)
{
try
{
sb.Append((char)b);
}
catch { };
}
MessageBox.Show(sb.ToString());
}
return sb.ToString();
}
catch { throw new Exception("Dosya okunurken hata oluştu."); }
finally { fs.Close(); fs.Dispose(); }
}
|
|
|
|
|
The bits I mentioned about BinaryReader working with primitives also applies to BinaryWriter.
Replace that with a fileStream, and it should work. If in doubt, look at your file content with a hex editor / viewer - I use PSPad which is freeware and available from PSPad[^] This will confirm you have the correct data written at the correct address.
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
I am using HexWorkshop as my hex editor and I could see the string that I wrote to the end of file but I wasn't checked that if my application find the correct location and apparently it wasn't finding the correct location so I should be working on my DigBinary method.
|
|
|
|
|
Hi Guys,
I have been trying to implement the KeyPress event on a listView so that when i use the DELETE key, i will delete the selected rows (MultiSelect=true)
The code works fine when i use a button to call it from :
private void btnDeleteRow_Click(object sender, EventArgs e)
{
while (listView1.SelectedIndices.Count > 0)
{
listView1.Items.RemoveAt(listView1.SelectedIndices[0]);
}
}
However in MSDN documentation it is explicitly said that e.KeyChar can't be used for DELETE and several other special function keys like F1-F12 , PageUp etc...
http://msdn.microsoft.com/en-us/library/system.windows.forms.keypresseventargs.keychar.aspx[^]
How can i use the DELETE KEY to delete items in listViews?
Kind regards,
Alex
“Be the change you want to see in the world.”
|
|
|
|
|
Perhaps the key up or key down event gets more eventargs ?
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
Thank you Christian, it works perfect with KeyDown and e.KeyCode.
Here is the implementation :
private void listView1_KeyDown(object sender, KeyEventArgs e)
{
if (listView1.SelectedItems.Count != 0 && e.KeyCode == Keys.Delete)
{
while (listView1.SelectedIndices.Count > 0)
{
listView1.Items.RemoveAt(listView1.SelectedIndices[0]);
}
}
}
“Be the change you want to see in the world.”
|
|
|
|
|
I don't know why keypressed doesn't get the same eventargs, but I had a feeling that was the case. There may be a systemkeypress event or similar, but I find keydown or keyup easier to deal with.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
For some reason[1], the normal control and navigation keys[2] are not exposed except in key down/up events. It's been this way as long as I can remember[3] and I can't see it changing soon. That would be sensible[4].
[1] I think Bill was drunk that day.
[2] The ones you are most likely to want to override.
[3] Ten years even after lunch.
[4] Should you actually want to write code.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
You should take care with this, it's not a good idea to make the change on the key down. I would recommend setting a flag when the button is pressed and checking for the flag when it's released, that is closer to the key pess event.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I had the same problem and i used this code:
private void listView1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Delete)
{
listView1.Items.RemoveAt(listView1.SelectedIndices[0]);
}
}
I hope this help you...
public void showSignature(object sender, MyForumSignatureEventArgs e)
{
signatureLabel.Text = e.Signature("MatheusMK3", "codeproject.com", "Forum");
}
|
|
|
|
|
I'm writing an Active Directory class in which I'd like to recreate the implementation of the OracleDataReader. For those of you not familiar, you can create an object in the typical fashion:
OracleDataReader reader = cmd.ExecuteReader(blah, blah);
The implementation is similar to the following:
while (reader.Read())
{
Add(reader["name"].ToString());
}
What's important to note is the fact that the Read() method returns a boolean. My ExecuteReader() method (I named mine something else) generates a DataView. I can envision the equivalent Read() method stepping through the DataView and returning this boolean value whether or not more records exist.
The item I'm stuck on is the implementation of access an object like a HashTable. I'm relatively new to the OOP world but I haven't seen this sort of access method before and am not sure how to implement it. Is this somehow overriding the array method?
I'd appreciate any tips on how to get started!
Thanks!
|
|
|
|
|
If you are trying to generate your own DataReader it must implement and adhere to System.Data.IDataReader, otherwise you are just creating a different entity with a confusing name. I would rethink your approach and make sure you are not reinventing the wheel.
The indexor on the datareader (reader["name"] in your code) calls dr.GetValue(dr.GetOrdinal("name")) and is really just a handy set of convenience methods. Also, note, that the type returned from reader["name"] is an object. ToString is only used to provide a string representation of an object not to cast objects. You should use the appropriate cast instead, ie: (string)reader["name"].
|
|
|
|
|
Hi,
I am getting problem to enum outlook folder using PIA.
I have namespace object, but how to enumerate outlook folder, Its confusing.
Microsoft.Office.Interop.Outlook.MAPIFolder Fldr=NspObj.Folders.GetFirst();
I am not able to find any interface to traverse the folder of outlook.
Please guide me.
|
|
|
|
|
Here's an example that recurses your outlook folder structure, looking for a named folder
using Microsoft.Office.Interop.Outlook;
...
Microsoft.Office.Interop.Outlook.Application outlook = new Microsoft.Office.Interop.Outlook.Application();
private Folder FindFolderRecursive(Folders start, string name)
{
foreach (Folder folder in start)
{
if (folder.Name == name)
{
return folder;
}
Folder found = FindFolderRecursive(folder.Folders, name);
if (found != null)
{
return found;
}
}
return null;
}
private void Form1_Shown(object sender, EventArgs e)
{
Folder stuff = FindFolderRecursive(outlook.Session.Folders, "Stuff")
foreach(Mailitem item in stuff.Items)
{
}
}
|
|
|
|
|
Thank you,
Please give me any link that fetch the email from a folder.
Or tell me how to do?
|
|
|
|
|
Erm - that's exactly what the snippet I posted does - it searches for a named folder then loops through all the mails in it.
|
|
|
|
|
|
Hi,
Whenever I tried to sort the mail item, it does not effect.
Microsoft.Office.Interop.Outlook.MAPIFolder mItem = TraverseTee(outlook.Session.Folders, "myfolder");
if(mItem!=null)
{
mItem.Items.Sort("Received", false);
int i=0;
foreach(Microsoft.Office.Interop.Outlook.MailItem item in mItem.Items)
{
listBox1.Items.Insert(i,item.Subject);
i++;
}
}
|
|
|
|
|
Is there a way to get the variable name in runtime ?
for example:
int number1=1;
int number2=2;
System.Console.WriteLine( PrintNameOfVariable(number1) );
System.Console.WriteLine( PrintNameOfVariable(number2) );
will write :
<br />
number1<br />
number2<br />
|
|
|
|
|
easy...
System.Console.WriteLine("number1");
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Hi,
I meant that im searching for a way to get the variable name.
For example if i have an object:
object aaa1 = somthig();
I want to get in runtime the variable name, in this case a string that conatin the value "aaa1".
|
|
|
|
|
some of these link[^]s may help
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
bonzaiholding wrote: Is there a way to get the variable name in runtime ?
AFAIK, not for local variables. You can use reflection to check what a class exposes, but you cannot see the names of locals.
|
|
|
|
|
I agree.
You can see the method parameters though, which basically are locals; they probably included those for supporting interface documentation.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|