|
In the documentation I linked, you can specify a sub-directory using the <probing> element in your application's .config file:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="plugins"/>
</assemblyBinding>
</runtime>
</configuration> Your .config file is named the same as your application with .config appended and located in the same application directory. For example, myapp.exe.config.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I use an XML file layout the steps to be completed by the program. Here is the general idea of the XML file:
<?xml version="1.0"?>
<DOC Name="TEST">
<STEP NAME="My Step 1" ID="1" TYPE="Type1">
<BLOCK NAME="TestBlock_1_1" NUMBER="68"></BLOCK>
<BLOCK NAME="TestBlock_1_2" NUMBER="35"></BLOCK>
</STEP>
<STEP NAME="My step 2" ID="2" TYPE="Type2">
<BLOCK NAME="TestBlock_2_1" NUMBER="42"></BLOCK>
<BLOCK NAME="TestBlock_2_2" NUMBER="26"></BLOCK>
</STEP>
</DOC>
I am reading the file fine, and can parse through and work with the STEP Elements. What I cannot get working is accessing the BLOCK elements within only a particular STEP
if(reader.Name=="STEP") //
{
reader.MoveToAttribute("NAME");
if(reader.Value == "My Step 1")
{
// How do I move to the Elements within this step??
// I need to know the BLOCK values
}
}
Thanks in advance for the help.
|
|
|
|
|
See the documentation for the XmlReader.ReadStartElement , which is implemented by derivatives of XmlReader .
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks,
That works for reading the next element, but I need to be able to read all the elements in that STEP. i.e. there could be multiple BLOCK tags and each would need to be read through in perhaps a foreach loop. The documentation on MSDN made it sound like that was only to read the next element? Perhaps I am confused.
Would appreciate any more help you can give.
The code in plain english should be:
foreach BLOCK element in STEP(Mystep)
//do code.
THanks so much
*****************
"I know how hard it is for you to put food on your family." —GW
|
|
|
|
|
Yes, it does only read the next element. You must call it again to move to the next element.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I was having a problem using a listbox that had been populated by using its datasource property to bind with my data. The problem arose if the data was also being updated in the same project from another view. The error that would occur is "cannot modify the items collection when the datasource property is set". Part of the answer to this problem was to avoid using the datasource property of the listbox and to populate the listbox instead by using the listbox item.add method. That kinda worked, which is of course infuriating since it would be nicer if it entirely worked! For some reason, the add.item method caused the listbox to display the following in the listbox window: "System.Data.DataRow". This then filled the entire window. My research informed me that you get this result if the listbox doesn't know the values of DisplayMember and ValueMember. But since I had supplied those with the pertinent info, I assumed something else was the problem. Here is a re-cap of everything I did, and what eventually solved the problem. (I end it all by asking why this fixed my issue? I like to know why things work on occasion)
ListBox control:
Here is what will work when using this control
option (1):
You can use MyListBox.DataSource=MyDataTable;
This will appear the easy way to go. The listBox will load up and appear fine. But if you have anyplace in your application that is making changes to the underlying data of MyDataTable, you will get the error:
"cannot modify the items collection when the datasource property is set"
So it seems that using MyListBox.DataSource=MyDataTable; has its problems.
option (2):
You can use a loop to load the ListBox collection like this:
for (int i=0; i < MyDataTable.Rows.Count; i++)
{
MyListBox.Items.Add(MyDataTable.Rows[i]);
}
This should eliminate the error in the earlier situation because the listBox collection is not Bound to an external source for data, so the external data source is free to have changes made to it.
But, unfortunately, and I don't know why... providing the data to the listbox this way causes the ListBox window to display a default series of "System.Data.DataRow" because the listbox is not able to recognize the DisplayMember and DisplayValues that you have provided. Oddly enough, it is still possible for you to select off of the listbox's window items, and recover the selected data value from a DataRow:
private void MyListBox_SelectedIndexChanged(object sender, System.EventArgs e)
{
DataRow oRow = (DataRow)MyListBox.SelectedItem;
MyTextBox.Text = oRow["MyFieldFromoRow"].ToString();
}
But this curiosity does not help us very much since what is displaying in the ListBox window is worthless.
If you want to use the listbox to display data from a table AND also have the datatable capable of being "changable" in the meantime. You must create a Class that wraps the DataTable data. This Class MUST use PROPERTIES to access the data. Then you must Create an ARRAY from the DataTable by passing each field value thru the class's properties while building the ARRAY in a load loop. Now, you can use the ListBox.Item.add in a for each loop using the resulting ARRAY we created above.
public void LoadListBox()
{
MyClass[] MyClassTab = FetchAllRowData(); // FetchAllRowData creates array using MyClass which MUST use properies to assin data values!
MyListBox.Items.Clear();
MyListBox.ValueMember = "MyValue_id";
MyListBox.DisplayMember = "MyTextValue";
foreach (MyClass E in MyClassTab)
{
MyListBox.Items.Add(E);
}
}
Whew. I am guessing that passing the DataTable data into an ARRAY that uses properties, and then using the resulting ARRAY for my ListBox must make the metadata available for the individual fields to be used by the DisplayMember and ValueMember ListBox properties. Is that why?
Does anybody out there know why I needed to do all this? Is this the way to go on this?
|
|
|
|
|
Hi,
I found an article that shows a simple way to open the default email client with some parameters set.
http://www.codeproject.com/dotnet/Default_mail_client.asp[^]
Only thing is: the attachment does not work.
(MsgBuilder.Append("&Attach=c:\mailattach.txt"))
Is there any way to open the default email with an attachment?
Thanks.
avivhal
|
|
|
|
|
As covered on this forum many times before (which is why the "Search comments" link above exists), not all MAPI clients support every syntax. It wasn't even that long ago that most MAPI clients like Outlook, Outlook Express, Netscape, and others supported the "Body" parameter. This also means that a client must have a MAPI client registered.
Rather than relying on what's installed - which gives you little to no control as you've found - send the mail yourself using SMTP. There are many articles here on Code Project as well as on this forum. You can also get third-party libraries like IP!Works[^].
Using the System.Web.Mail namespace is also a bad idea because it requires a CDO library for the system. Only Win2K and above have this client library. NT4 uses something else, IIRC, and Windows 98/Me have nothing.
True SMTP support is being added to the .NET Framework for "Whidbey" (.NET 2.0) to replace this hazardous namespace.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hai all,
Somebody help me in this issue. I need to have a menu bar which is
RightToLeft aligned, which I can achieve by setting MainMenu's RightToLeft
property to "Yes". The problem that I get is, if one of MenuItems has
submenu...the arrow(or small triangle which indiates it has submenu) appears
in the left. I wanted to know when is this getting drawn. I want to trap
that and draw my own image to indicate that it has submenu. Below is the
code that I have written for DrawItem and MeasureItem for each MenuItem. Any
help is greatly appreciated.....
Thanks,
Madhavi.
private void menuItem1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
Rectangle rc = new Rectangle(e.Bounds.X+1 , e.Bounds.Y+1, e.Bounds.Width,
e.Bounds.Height-1);
e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(51,102,153)), rc);
MenuItem s = (MenuItem)sender ;
RedrawSubMenuItems(s);
string s1 = s.Text +" |" ;
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Near ;
e.Graphics.DrawString(s1 , new Font("Ariel" ,9, FontStyle.Bold), new
SolidBrush(Color.FromArgb(255,255,128)) , rc , sf );
Console.WriteLine(e.State.ToString());
if ( e.State == (DrawItemState.NoAccelerator | DrawItemState.Selected) ||
e.State == ( DrawItemState.NoAccelerator | DrawItemState.HotLight) )
{
//e.Graphics.FillRectangle(new SolidBrush(Color.LightYellow) , rc);
e.Graphics.DrawString( s.Text , new Font("Ariel" , 9 , FontStyle.Bold |
FontStyle.Underline ) , new SolidBrush(Color.FromArgb(255,255,128)), rc
,sf);
//e.Graphics.DrawRectangle(new Pen(new SolidBrush(Color.Black)), rc );
}
|
|
|
|
|
Well I am knee deep into my first foray into socket programming. So i have a windows server based application that will listen for client requests and based on client requests does X Y Z. Well, I implemented a threadpool on the processing side, but I have found a major whole in my code. The socket seems to be only letting in once connection at a time. Yep, I did not implement thread pool on that end. So, does anyone have a sample code that I can use as a guideline to implement this or suggest somehting.
There was an article on code project that I cannot remember for the life of me. It dealt with getting a connection status of people connected to a server.
|
|
|
|
|
A quick search[^] on this site for "socket thread" yields many articles.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have a binary which I wish to save to my local disk. I want to use a filestream to save this binary to my hard disk. In the case that it is already there, I want to delete it and then save it.
I used this code:
// Local is some file location
FileInfo fi = new FileInfo(local);
if(fi.Exists)
fi.Delete();
FileStream fstr = fi.Create();
fstr.Write(openedBinary, 0, openedBinary.Length);
fstr.Flush();
fstr.Close();
However, in the next line, I have another function that makes use of this binary which is now locally stored. SOMETIMES, that works, usually it doesn't. I don't quite know why! Can someone tell me why this would act unpredictably?
Cheers,
Jim
|
|
|
|
|
Okay, here's just one more thing i discovered. When I put a breakpoint on my open command, open the file externally (i.e. in Windows Explorer) close it, and THEN execute the open command it works. Its not a matter of waiting for a period of time, no matter how long I wait the open command won't work if I don't go and actually open the file.
Cheers,
Jim
|
|
|
|
|
Are you using a FileDialog control someplace in your application? The first thing you might want to try is simply using the full path for your file (local). That will probably solve your problem...
-DougW48
dwright@tdci.com
|
|
|
|
|
There's two things you must keep in mind - the application directory and the current working directory. When you start an application, the current working directory may not necessarily be the same as the application directory. Double clicking the EXE would yield this result, but a shortcut to your application may define a different working directory. A working directory can also be changed at runtime (i.e., while your application is running).
If you want that file to always be relative to your application, use the Application.StartupPath like so:
string filename = Path.Combine(Application.StartupPath, "file.dat"); Without specifying a full path starting from the drive path, the current working directory is used to resolve the file path.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I have a service that I built which sends emails out to subscribers which I have been testing for the past two weeks. I want to launch it into release mode running on my computer as a service, but I also want to be notified when the 'job' starts so I can monitor the logs.
I thought that I might like to have my computer beep a half dozen times when the job starts so that I will be notified.
However, it is a service therefore no window and no reference to windows.forms. I search through MSDN and codeproject and found many references to using DirectX and using MessageBeep but I don't really want to increase the size of my project to have references to large namespaces which will not really be used.
Is there another way to access the pc speaker and emit a tone via a service? If not, any other ideas how I could notify myself when a service starts processing work?
Tim
|
|
|
|
|
I have no idea if this actually works still in c#, or if you can do it in a service...but when I used to use C/C++, I would output \a to produce a generic system beep. In C++ it looked like this:
cout << "\a";
You might want to look at that as an option...
Good luck
- DougW48
dwright@tdci.com
|
|
|
|
|
That brought me back to Borland Turbo C and printf("\a")!
I tried Console.Write("\A") which I believe is the C# equivalent and unfortunately it didn't work...
Tim
|
|
|
|
|
Won't work since you don't have a desktop, UI, CONSOLE WINDOW to output anything to. So, no beep...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
You can call the native implementation, you just need to P/Invoking the signature. The following will allow you to call MessageBeep .
[DllImport("user32.dll")]
static extern bool MessageBeep(uint uType);
|
|
|
|
|
A service can actually interact with the desktop because it can create a window station either one of two ways.- Run the service as SYSTEM and check the interactive option. This is highly discouraged, however, because a service rarely needs SYSTEM (like Administrative) privileges.
- Run the service as a user with interactive login rights. That user can still login interactively, but the service runs as that user. A separate window station (which hosts a desktop) is created for both.
You can read more about Windows Services - in general - at http://msdn.microsoft.com/library/en-us/dllproc/base/services.asp[^].
I am planning on releasing a new article about this hopefully this weekend if I get time to finish it up, so keep an eye on my articles if you'd like.
You could simply P/Invoke the native Beep API:
[DllImport("kernel32.dll", SetLastError=true)]
static extern bool Beep(
[MarshalAs(UnmanagedType.U4)] int dwFreq,
[MarshalAs(UnmanagedType.U4)] int dwDuration);
public void Beep()
{
if (!Beep(256, 500))
throw new Win32Exception();
} This is by far more simple.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Damn! :-> Beat me to it!
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello,
I'm trying to find a way to determine the size of the text in a LinkLabel. I want it to automatically resize itself. Other controls have a ContentsResized event, but the LinkLabel is sadly lacking. Any ideas? I was thinking that I could create a Graphics object from the control and call MeasureString to get the size of its text - when would be the best time to do this?
Will
|
|
|
|
|
Handle it in the TextChanged event. You are on the right track with using the MeasureString graphics object.
Good luck
- DougW48
dwright@tdci.com
|
|
|
|
|
That does make sense now that I've woken up a bit.
Thanks,
Will
|
|
|
|
|