|
Thanks a lot. It works fine when server name is replaced with ip address.
|
|
|
|
|
Hi
How can I create and write files with C#
For instance, I have a file on my C drive. I want to create the same file on D drive.
Is there an example on the web that I can follow to create & write Files.
(in future, I would also need to upload files to my Web server space without using HttpPostedFile)
Any help appreciated
Regards
|
|
|
|
|
google around before you ask a question like that...
check for System.IO.File class... it has all the methods you need like copy create etc. it also has streamreader and writer to enable you editing files.
-- modified at 6:23 Friday 7th April, 2006
|
|
|
|
|
Thanks
Whenever, I post a question, I do a thorough search on Google.
But unfortunately, I did not find any example.
regards
|
|
|
|
|
ok... anyway i think that tnow when you know which class to use you can do it, because it's quite intuitious.
regards
|
|
|
|
|
hi All,
I am attaching the code of my C# console application. it is a keyboard hook. but its not working.. the program exits b4 any key is pressed.
using System;
namespace hooksample
{
using System;
using System.Runtime.InteropServices;
namespace hooks
{
public class Class1
{
#region Hook Variables
public struct KeyboardHookStruct
{
public long vkCode;
public long scanCode;
public int flags;
public long time;
public long dwExtraInfo;
};
private const int HC_ACTION = 0;
private const int LLKHF_EXTENDED = 0x01;
private const int LLKHF_ALTDOWN = 0x20;
private const long VK_T = 0x54;
private const long VK_P = 0x50;
private const long VK_W = 0x57;
private const int VK_TAB = 0x9;
private const int VK_CONTROL = 0x11;
private const int VK_ESCAPE = 0x1B;
private const int WH_KEYBOARD_LL=13;
protected IntPtr KeyboardHandle = IntPtr.Zero;
private static int mHook;
#endregion
public Class1()
{
Install();
}
public static void Main()
{
Class1 classnew =new Class1();
}
#region Hook Functions
private delegate int KeyboardHookProcDelegate(int nCode, int wParam, int lParam);
public static int KeyboardHookProc(int nCode, int wParam, int lParam)
{
KeyboardHookStruct HookStruct;
int ret = 0;
Console.WriteLine("inside HookProc");
HookStruct = ((KeyboardHookStruct) Marshal.PtrToStructure(new IntPtr(lParam), typeof(KeyboardHookStruct)));
long vkCode= HookStruct.vkCode;
int flag = HookStruct.flags;
if(nCode==HC_ACTION)
{
Console.WriteLine("inside nCode==HC_ACTION");
if(vkCode == VK_T )
{
Console.WriteLine(" found T ");
if((GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0)
{
Console.WriteLine("Play");
ret=1;
}
else if((flag & LLKHF_ALTDOWN)!=0)
{
Console.WriteLine("Stop");
ret=1;
}
}
else if(vkCode == VK_P)
{
Console.WriteLine(" found P ");
if((GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0)
{
Console.WriteLine("pause");
ret = 1 ;
}
}
else if(vkCode == VK_W)
{
Console.WriteLine(" found W ");
if((GetAsyncKeyState(VK_CONTROL) & 0x8000) != 0)
{
Console.WriteLine("Save");
ret = 1 ;
}
}
}
if( ret == 0 )
{
ret = CallNextHookEx(mHook,nCode,wParam,lParam);
}
return ret;
}
public void Install()
{
Console.WriteLine("inside Install");
mHook=SetWindowsHookEx(WH_KEYBOARD_LL,new KeyboardHookProcDelegate(KeyboardHookProc),IntPtr.Zero,(int)AppDomain.GetCurrentThreadId());
if(mHook!=0)
{
Console.WriteLine("unable to install");
}
else
Console.WriteLine("Success in Installing!");
}
public void UnInstall()
{
Console.WriteLine("inside UnInstall");
if(mHook!=0)
{
Console.WriteLine("inside mHook!=0 ");
UnhookWindowsHookEx(mHook);
}
}
#endregion
#region Hook Win32Imports
[DllImport("user32.dll")]
private static extern int SetWindowsHookEx(int code,
KeyboardHookProcDelegate func,
IntPtr hInstance,
int threadID);
[DllImport("user32.dll")]
protected static extern bool UnhookWindowsHookEx(int hhook);
[DllImport("user32.dll")]
protected static extern int CallNextHookEx(int hhook,
int code, int wParam, int lParam);
[DllImport("user32.dll")]
private static extern short GetAsyncKeyState(int vKey);
#endregion
}
}
}
i need to know whether i have done the hook correctly?
y its not working?
waiting for a reply.
thanks in advances.
lmhp
|
|
|
|
|
|
hello,
thanks .but i have tried to use this.But it is not doing the required work.This made me develope my own code.
Both in same state on.Please suggest me a solution.
thanks.
lmhp
|
|
|
|
|
A console application does not have a Windows message loop. You need to wait - for something. Your Main method just loads the class, then terminates.
BTW: When did you plan on calling UnInstall?
----------
There go my people. I must find out where they are going so I can lead them.
- Alexander Ledru-Rollin
|
|
|
|
|
I would like to open a pdf file such as (Data mining.pdf).
But I only know how to create a pdf file and not to read it.
So please give me some suggestion how I can read a pdf file.
May Thu San
|
|
|
|
|
Hi,
This link is pretty good.
http://www.codeproject.com/csharp/MgPDFReader.asp
Regards,
Visala.
|
|
|
|
|
Hi,
I want to compare two xml files using C# code.I am having two files like abc.xml and cdf.xml..I want to compare the content of both files same or not.Please address me if any thing got idea.
Regards,
Visala.
visal k
|
|
|
|
|
one method: use this to load xml file into a dataset and then compare them.
DataSet ds=new DataSet();
ds.ReadXml("filename");
|
|
|
|
|
I need simple example please..Because I am new to C#..Could u please provide me sample example files and send me the code for comparision.Please
Regards,
Visala.
|
|
|
|
|
I have a server that exposes some classes through .NET Remoting.
If these classes have events, can the client subscribe them by simply using the usual syntax Event += new EventHandler(...), after getting a reference to the remote object?
Perhaps I'm asking an idiocy.
___________________________________
Tozzi is right: Gaia is getting rid of us.
My Blog [ITA]
|
|
|
|
|
Yes they can, and that is the beauty of remoting, you can use remote objects just like local ones.
You need to be aware of potential security exceptions though, because when the server fires an event, communication is happening in the opposite direction (when compared to a method call). Specifically, you'd need to set the typeFilterLevel[^] to allow two way communication. And of course, if your client is behind a firewall that blocks all incoming traffic, it's not going to get the events.
Regards
Senthil
_____________________________
My Blog | My Articles | My Flickr | WinMacro
|
|
|
|
|
Thanks for your reply!
S. Senthil Kumar wrote: if your client is behind a firewall that blocks all incoming traffic, it's not going to get the events
I thought that, when you get an instance of the remote object, the network connection is kept open until you destroy it. Am I wrong?
___________________________________
Tozzi is right: Gaia is getting rid of us.
My Blog [ITA]
|
|
|
|
|
Yes, but you need a different socket connection for events, as the role is reversed i.e client becomes server and server becomes client, because it's the server that initiates the call.
Regards
Senthil
_____________________________
My Blog | My Articles | My Flickr | WinMacro
|
|
|
|
|
any one know why the key down don't work?
thanks
|
|
|
|
|
because there is some bug in your code probably. paste us a snippet responsible for that...
|
|
|
|
|
Did you set the forms KeyPreview property to True?
Roy.
|
|
|
|
|
I have an array of bit values - well actually a bool array, 8 elements long. How can I convert this into it's byte representation?
So basically, I want to do a binary to decimal conversion. How can I do this?
/\ |_ E X E GG
|
|
|
|
|
Create a BitArray from the array of booleans and use the CopyTo method to store the value in an array of byte (with the size of one).
---
b { font-weight: normal; }
|
|
|
|
|
OK Thanks. I found a nice library on this site also...
/\ |_ E X E GG
|
|
|
|
|
If it's just an 8-bit to byte conversion this will do the job:
byte value = 0;
bool[] bits = { false, true, true, false, true, false, false, true };
for (byte b = 0; b < bits.Length; b++)
{
value <<= 1;
if (bits[b])
value |= 0x1;
}
This will also work if you change byte to int and increase the array length to a maximum of 32 boolean values
regards
modified 12-Sep-18 21:01pm.
|
|
|
|