|
|
Like the post from edboe, obfuscate the code. There are plently of good tools out there to do this
Here is a turn up from my google[^] search.
|
|
|
|
|
Hi,
i am creating a form to display the actions done to file in a directory.
For the add, delete and rename actions a write line in a textbox.
The directory is accessible through a windows share (on my local machine) and now i am trying to get the username of some external user who is also modifying files on my shared directory.
How can this be done? i now only get the username of the logged in user (being myself ...)
|
|
|
|
|
Hi ,
i want to make a utility using c# similar to replace function in the notepad. i have a file in which i want to replace the all the instances of a string with another string.
Help me in doing that .........
thanks and regards
sankalp verma
Sankalp Verma
|
|
|
|
|
Open the file and read the contains of the file to a string.
Then use, for example:
string myText = myText.Replace("apple", "mango");
|
|
|
|
|
But i have to save the contents to the file also.........
how do i save them into the file?
Sankalp Verma
|
|
|
|
|
Use StreamWriter. Read MSDN.
|
|
|
|
|
Hi there,
I have the following problem:
I want to add a variable 'myServerInfo' to an arraylist.
This variable is of the datatyp 'ServerInfo' (public class).
I can add this variable without any problems to the arraylist with
the command:
<br />
myServerArrayList.Add(myServerInfo);<br />
But how can I have access to this through the arraylist?
If I type in the following commandline, Intellisense will not
provide me the necessary information:
<br />
Console.WriteLine(myServerArrayList[0].???<br />
I thought I can type in:
<br />
Console.WriteLine(myServerArrayList[0].strServerName);<br />
Console.WriteLine(myServerArrayList[0].strServerIP);<br />
Console.WriteLine(myServerArrayList[0].strServerNetMask);<br />
My complete code for this example is like:
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Collections;<br />
<br />
namespace ConsoleApplication1<br />
{<br />
public class ServerInfo<br />
{<br />
public string strServerName;<br />
public string strServerIP;<br />
public string strServerNetMask;<br />
}<br />
<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
ArrayList myServerArrayList = new ArrayList();<br />
ServerInfo myServerInfo = new ServerInfo();<br />
myServerInfo.strServerName = "Server 1";<br />
myServerInfo.strServerIP = "192.168.0.1";<br />
myServerInfo.strServerNetMask = "255.255.255.0";<br />
myServerArrayList.Add(myServerInfo);<br />
Console.WriteLine(myServerArrayList[0].???<br />
}<br />
}<br />
}
If anybody gives me a hint,
I can go on with my project.
Thanks in advance
Erik
|
|
|
|
|
What you get from the ArrayList is a reference to the type Object. You have to cast the reference to the actual data type:
(ServerInfo)(myServerArrayList[0])
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
I tried
MessageBox.Show((ServerInfo)(myServerArrayList[0]).strServerName);
but it won't work
'Object has no definition for strServerName'
Erik
|
|
|
|
|
In (ServerInfo)(myServerArrayList[0]).strServerName ...
It won't if the cast is applied after having attempted to retrieve the strServerName in (myServerArrayList[0]) which is recognized as an object type instance.
|
|
|
|
|
Add parentheses so that you access the property of the ServerInfo object, not the Object object.
MessageBox.Show(((ServerInfo)(myServerArrayList[0])).strServerName);
---
b { font-weight: normal; }
|
|
|
|
|
Since anything derived from object can be stored in your ArrayList, Intellisense does not "know" what kind of object is stored in the 0th position. You need to cast it before: ((ServerInfo)myServerArrayList[0]). ... or use something more appropriate than ArrayList. Try List<ServerInfo>
|
|
|
|
|
You have to cast it since it returns an object:
(myServerArrayList[0] as myServerInfo).strServerName
|
|
|
|
|
This works perfect!
Thanks a lot
|
|
|
|
|
make sure you only have serverinfo in that arraylist though
item as ServerInfo will return null if item is not a serverinfo, this will create a runtime error. If you can and you are using 2005 i would try to use one of the generic collection types Collection<serverinfo> or List<serverinfo> as someone else suggested later. That's more likely to show errors at compile time.
HTH
Russ
|
|
|
|
|
Thanks a lot for this detailed information!!
|
|
|
|
|
Arrays store System.Object type. When you add a new object or an item of promotive type they will be upcasted to System.Object. This is the line inside ArrayList which adds the new item:
public virtual int Add(object value); Use Code DEfinition Window in VS 2005 to see what's inside ArrayList class.
In order to access properties you need to down cast the array item you want to acces like:
Console.WriteLine(((ServerInfo)myServerArrayList[0]).PropertyName);
You would have the same problem if you tried:
ArrayList myList = new ArrayList();
int int1 = 1;
myList.Add(int1);
int int2 = 2;
myList.Add(int2);
int int3 = myList[0]; // oops error - cannot convert type 'object' to 'int'
int int3 = (int)myList[0]; // this will do the trick
Happy coding ...
|
|
|
|
|
Hi.
Does anyone know how can I make a control work without recieving the focus?
The thing is that I'm trying to simulate a kyboard (on a UserControl) which is added to a form. Whenevet a key is clicked, I use the SendKeys.SendWait method to simulate a keystroke. In order to process the simulated keystroke, the recieving form should be in focus. To achieve this, I use the SetFocus function (from User32.dll) with the handler of the recieving form. So far so good - it all works fine except for the slight occasional control bar flicker when changing the focus.
So - is there a way to avoid all that focus transfer?
|
|
|
|
|
hi all,
i have a Tree with 3 modes. each tree has 1 child. i need to create 2 context menus;one for all the nodes and the other for all the children programmatically
kindly help
Sonu
|
|
|
|
|
Hi,
have a look to my example:
I created a windows-application with a form
and one 'TreeView'-component named treeView1 in my code.
The only code is written within the Load-event of the form:
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
ContextMenu myRootContextMenu = new ContextMenu();<br />
myRootContextMenu.MenuItems.Add("Edit Root");<br />
<br />
ContextMenu myChild1ContextMenu = new ContextMenu();<br />
myChild1ContextMenu.MenuItems.Add("Edit Child 1");<br />
ContextMenu myChild2ContextMenu = new ContextMenu();<br />
myChild2ContextMenu.MenuItems.Add("Edit Child 2");<br />
<br />
<br />
TreeNode rootTreeNode = new TreeNode("Root");<br />
rootTreeNode.ContextMenu = myRootContextMenu;<br />
rootTreeNode.Nodes.Add("First Node");<br />
rootTreeNode.Nodes[0].ContextMenu = myChild1ContextMenu;<br />
rootTreeNode.Nodes.Add("Second Node");<br />
rootTreeNode.Nodes[1].ContextMenu = myChild2ContextMenu;<br />
<br />
treeView1.Nodes.Add(rootTreeNode);<br />
}<br />
I created one root treenode 'rootTreeNode'
TreeNode rootTreeNode = new TreeNode("Root");
and
added two child nodes:
rootTreeNode.Nodes.Add("First Node");<br />
rootTreeNode.Nodes.Add("Second Node");
After that, I added this treenode to the TreeView 'treeView1'
of the Form.
treeView1.Nodes.Add(rootTreeNode);
Now we come to the context-menues:
I created one root context-menu, and gave it a description
ContextMenu myRootContextMenu = new ContextMenu();<br />
myRootContextMenu.MenuItems.Add("Edit Root");
and with the property 'ContextMenu' of the rootTreeNode
rootTreeNode.ContextMenu = myRootContextMenu;
I made the assignment.
The context-menues for the child nodes are
ContextMenu myChild1ContextMenu = new ContextMenu();<br />
myChild1ContextMenu.MenuItems.Add("Edit Child 1");<br />
ContextMenu myChild2ContextMenu = new ContextMenu();<br />
myChild2ContextMenu.MenuItems.Add("Edit Child 2");
and assigned in the same way.
Hope this helps a little bit
Regards
Erik
|
|
|
|
|
Db2 is running on as400. We want to have a copy of the data on a windows server with ms sql server.
a. Is there an odbc driver for db2 so we can query db2 from within ms sql server?
b. More in general: how can we copy data from db2 to ms sql server and maybe automate this?
c. what else do we need to know or is there some guide available online.
|
|
|
|
|
There are a few ODBC drivers available for DB2. Google it up! As for copy data between DB2 and SQL Server. Is like a replication system or a one time only process? Do you want to transfer bulk volumes of data or small amounts of it?
I dont know much about the performance aspects of it but if you had ODBC drivers for DB2, couldn't you just query the data from DB2 and insert it into SQL Server and vice versa?
|
|
|
|
|
how can we convert g.DrawImage(image,rect,pixenUnit)
to bitmap Image
|
|
|
|
|
Bitmap bmpMyImage = new Bitmap(image);
- - - --[ i love it when a plan comes together ]-- - - -
|
|
|
|