|
Quite simply just what the title says.
What i want to do is have all of my files built into the app, but i cant seem to play a music file from the resources so i want to move it to a temporary folder, play it there, then delete it when im done.
|
|
|
|
|
Fine leave me to die... I'll just come back to haunt you, HAUNT YOU ALL I SAY
|
|
|
|
|
Hi,
When my file is right clicked, under the version tab,there are details like file version & language. May i know how to retrieve these details of that file in C# program(without right clicking)
|
|
|
|
|
what kind of file? If it is .NET assembly - reflection. If not, it's Win32 resource (IIRC)... I don't know how to get it from executable... but PE is documented format, right? must be on the web...
e.g here[^]
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
I need to find for the files such as bootstrap.exe or instmsiw.exe-installer for the windows installer
|
|
|
|
|
|
|
First question - I've run into what appears to be a very odd behavior. I create a custom type converter based on ExpandableObjectConverter. Assign it to a class using the TypeConverter attribute. Nothing happens - the PropertyGrid displays the property disabled and extracting PropertyDescriptor for it I can see that the converter field is null. What is going on here ? Why was the custom converter not assigned? For a sanity check - if I set the converter to be the base ExpandableObjectConverter then it works fine and the converter is properly assigned.
All the classes are contained within one source file. Perhaps there is some order of instantiation problem going on?
Second question - how do I modify property attributes at run-time? For instance on certain occasions I would like to disable certain properties ( or, if possible - prevent them from being shown in the grid at all ). I can find PropertyDescriptors for each property but all the fields I'm interested in are read-only.
Thanks for any help!
Disclaimer: I'm farily new to C# so excuse my ignorance if the above questions are trivial or just plain dumb
|
|
|
|
|
Hey!
I have the following XML containt
<br />
-<br />
<settings><br />
<Port>0</Port><br />
<StopBits>4</StopBits><br />
<Parity>2</Parity><br />
<BoudRate>9</BoudRate><br />
<DataBits>4</DataBits><br />
<AddTimeStamp>True</AddTimeStamp><br />
<SaveToFile>True</SaveToFile><br />
<SizeOfWindow>MEDIUM</SizeOfWindow><br />
<MountedDisplay>True</MountedDisplay><br />
</settings>
I am using this C# code to fetch it:
<br />
xTR = new XmlTextReader("PortSettings.xml");<br />
xTR.MoveToContent();<br />
<br />
while (xTR.Read())<br />
{<br />
if (xTR.NodeType == XmlNodeType.Element)<br />
{<br />
switch (xTR.Name)<br />
{<br />
case "Port":<br />
MessageBox.Show("Port : " + xTR.ReadElementString("Port"));<br />
break;<br />
case "StopBits":<br />
MessageBox.Show("StopBits : " + xTR.ReadElementString("StopBits"));<br />
break;<br />
case "Parity":<br />
MessageBox.Show("Parity : " + xTR.ReadElementString("Parity"));<br />
break;<br />
case "BoudRate":<br />
MessageBox.Show("BoudRate : " + xTR.ReadElementString("BoudRate"));<br />
break;<br />
case "DataBits":<br />
MessageBox.Show("DataBits : " + xTR.ReadElementString("DataBits"));<br />
break;<br />
case "AddTimeStamp":<br />
MessageBox.Show("AddTimeStamp : " + xTR.ReadElementString("AddTimeStamp"));<br />
break;<br />
case "SaveToFile":<br />
MessageBox.Show("SaveToFile : " + xTR.ReadElementString("SaveToFile"));<br />
break;<br />
case "SizeOfWindow":<br />
MessageBox.Show("SizeOfWindow : " + xTR.ReadElementString("SizeOfWindow"));<br />
break;<br />
case "MountedDisplay":<br />
MessageBox.Show("MountedDisplay : " + xTR.ReadElementString("MountedDisplay"));<br />
break;<br />
default:<br />
break;<br />
}<br />
}<br />
}<br />
xTR.Close();<br />
Problem: It only read Port, Parity, DataBits, SaveToFile and Monted Display. With other words its only reads every other.
Probley this is a simple mistake, pleas help.
Best Regards
SnowJim
|
|
|
|
|
tries the XML file again
<br />
<?xml version="1.0"?><br />
<!--Settings for TerminalSoftware--><br />
<!--By Changing this settings manually could result in instability. <br> This XML file is generated from TerminalSoftware.saveProgramSettings()--><br />
<br />
<settings><br />
<Port>0</Port><br />
<StopBits>4</StopBits><br />
<Parity>2</Parity><br />
<BoudRate>9</BoudRate><br />
<DataBits>4</DataBits><br />
<AddTimeStamp>True</AddTimeStamp><br />
<SaveToFile>True</SaveToFile><br />
<SizeOfWindow>MEDIUM</SizeOfWindow><br />
<MountedDisplay>True</MountedDisplay><br />
</settings>
I know that there is nothing wrong with the XML, it should be the C# code.
|
|
|
|
|
There most be a simple explenation for this, and how to solve it? Else XML will be as good as regular text file in this case.
SnowJim
|
|
|
|
|
Im not 100% sure but I think the ReadElementString function also calls Read internally. Thus every call of this function will result in making the reader moving forward twice.
You could do something like this (although there is probably a more elegant solution):
xTR = new XmlTextReader("PortSettings.xml");
xTR.MoveToContent();
ArrayList neededElements = new ArrayList();
neededElements.Add("Port");
neededElements.Add("StopBits");
neededElements.Add("Parity");
neededElements.Add("BoudRate");
neededElements.Add("DataBits");
neededElements.Add("AddTimeStamp");
neededElements.Add("SaveToFile");
neededElements.Add("SizeOfWindow");
neededElements.Add("MountedDisplay");
while (xTR.Read())
{
if (xTR.NodeType == XmlNodeType.Element)
{
if (neededElements.Contains(xTR.Name)) {
MessageBox.Show(xTR.Name + " : " + xTR.Value);
}
}
}
xTR.Close();
(I only added the ArrayList thing to keep the code short )
|
|
|
|
|
Robert Rohde wrote:
Im not 100% sure but I think the ReadElementString function also calls Read internally
yup, it does call both XmlReader.MoveToContent() and XmlReader.Read .
At least in Rotor, but 99% in MS .NET framework too.
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
Dont realy understand how this could give me the information that every element have? value is ""
SnowJim
|
|
|
|
|
|
|
Its the same thing with xTR.InnerText.
SnowJim
|
|
|
|
|
How come this works?? (I copied your snippet & XML file + changed MessageBox cuz it's VERY bad way how to debug loops!)
xTR.MoveToContent();
while (xTR.Read())
{
if (xTR.NodeType == XmlNodeType.Element)
{
switch (xTR.Name)
{
case "port":
Console.WriteLine("Port : " + xTR.ReadInnerXml());
break;
case "stopbits":
Console.WriteLine("StopBits : " + xTR.ReadInnerXml());
break;
case "parity":
Console.WriteLine("Parity : " + xTR.ReadInnerXml());
break;
...
for this XML file:
<?xml version="1.0" encoding="utf-8" ?>
<settings>
<port>0</port>
<stopbits>4</stopbits>
<parity>2</parity>
<boudrate>9</boudrate>
<databits>4</databits>
<addtimestamp>True</addtimestamp>
<savetofile>True</savetofile>
<sizeofwindow>MEDIUM</sizeofwindow>
<mounteddisplay>True</mounteddisplay>
</settings>
gives me output:
Port : 0
StopBits : 4
Parity : 2
BoudRate : 9
DataBits : 4
AddTimeStamp : True
SaveToFile : True
SizeOfWindow : MEDIUM
MountedDisplay : True
Press any key to continue (console app in debug mode)
However I had to change strings in switch... (it's case sensitive)
I was wrong InnerText is property of XmlElement not of XmlReader .
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
Thanks alot!
I will not use MessageBox to debug, thats forsure!
But i did manage to read the content another way, but im not sure if its faster or slower.
<br />
XmlDocument doc = new XmlDocument();<br />
doc.Load("PortSettings.xml");<br />
<br />
XmlNode node;<br />
<br />
node = doc.GetElementsByTagName("Port")[0];<br />
if(node != null)<br />
cbConfigPorts.SelectedIndex = int.Parse(node.InnerText);<br />
<br />
node = doc.GetElementsByTagName("StopBits")[0];<br />
if (node != null)<br />
cbConfigStopBits.SelectedIndex = int.Parse(node.InnerText);<br />
<br />
node = doc.GetElementsByTagName("Parity")[0];<br />
if (node != null)<br />
cbConfigParity.SelectedIndex = int.Parse(node.InnerText);<br />
<br />
node = doc.GetElementsByTagName("BoudRate")[0];<br />
if (node != null)<br />
cbConfigBoudRate.SelectedIndex = int.Parse(node.InnerText);<br />
<br />
node = doc.GetElementsByTagName("DataBits")[0];<br />
if (node != null)<br />
cbConfigBits.SelectedIndex = int.Parse(node.InnerText);<br />
<br />
node = doc.GetElementsByTagName("AddTimeStamp")[0];<br />
if (node != null)<br />
cbConfigAddTimeStampToStream.Checked = bool.Parse(node.InnerText);<br />
<br />
node = doc.GetElementsByTagName("SaveToFile")[0];<br />
if (node != null)<br />
cbConfigSaveMainstreamToFile.Checked = bool.Parse(node.InnerText);<br />
<br />
node = doc.GetElementsByTagName("SizeOfWindow")[0];<br />
if (node != null)<br />
changeWindowSize(int.Parse(node.InnerText));<br />
<br />
node = doc.GetElementsByTagName("MountedDisplay")[0];<br />
if (node != null)<br />
incomeLoggDisplay.loggDisplayOnOff = bool.Parse(node.InnerText);<br />
<br />
doc = null;<br />
<br />
This works good to!
Many thanks for your time!
Best Regards
SnowJim
|
|
|
|
|
hi,
It may be slightly slower - after all XmlDocument internally uses XmlReader . Main problem with XmlDocument is that it constructs whole DOM in memory - which makes it unusable for biger files and slower/more resource expensive for "medium-sized" files.
But XmlDocument is really good when it come to tree operations with XML data.
One more solution would be use of XPathDocument , it's smaller overkill then XmlDocument (but slower/more expensive then XmlReader s) and it's fairly easy to use... actualy same use as XmlDocument in this case.
David
Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy
|
|
|
|
|
Thanks for the information =) in this case i will stick to XmlDocument becourse the xml file is not to big, and i will only use it when the program opens and close
BestRegards
SnowJim
|
|
|
|
|
Hello,
I want to periodically send a TCP packet to a peer, always from the same source port. That is, each packet will come from my local ip address, port 8801, and go to the peer's ip address, to HIS port 8801.
This means that I need to bind my sender socket to (myaddress,8801), use it for the send, then shut it down and close it. Then I want to wait, say 30 seconds, and do it all over again. Naturally, the socket's ReuseAddress property must be set for this to work.
However, in practice, the second time I bind a socket to my local endpoint, I get a SocketException: "Only one usage of each socket address (protocol/network address/port) is normally permitted."
Can anyone help me? The following code attempts to send a string containing the date/time to a server on 192.168.2.10:8810. If I set the "bindIt" variable to false, the code works fine. If I try to bind (and re-bind) the socket to the same local endpoint (e.g, I've set bindIt to true), the code fails with the above exception. Help!
Thanks
Greg Hassett
using System;<br />
using System.IO;<br />
using System.Net;<br />
using System.Net.Sockets;<br />
using System.Text;<br />
using System.Threading;<br />
<br />
class TcpClientTest <br />
{<br />
static public void Main() <br />
{<br />
bool bindIt = true;<br />
<br />
IPHostEntry localHostEntry = Dns.GetHostByName(Dns.GetHostName());<br />
IPEndPoint localIPEndPoint = new IPEndPoint (localHostEntry.AddressList[0], 8801);<br />
<br />
while (true)<br />
{<br />
try<br />
{<br />
Console.WriteLine("Press return to send data");<br />
Console.ReadLine();<br />
<br />
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);<br />
<br />
socket.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);<br />
socket.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.Linger, new LingerOption(false, 0));<br />
socket.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.DontLinger, 1);<br />
<br />
if (bindIt)<br />
{<br />
socket.Bind (new IPEndPoint (IPAddress.Any, 8801));<br />
}<br />
<br />
socket.Connect (new IPEndPoint(IPAddress.Parse("192.168.2.10"), 8801));<br />
<br />
byte[] buf = Encoding.ASCII.GetBytes (DateTime.Now.ToString());<br />
socket.Send (buf);<br />
<br />
socket.Shutdown (SocketShutdown.Both);<br />
socket.Close ();<br />
<br />
Console.Out.WriteLine ("Sent");<br />
}<br />
catch (Exception ex)<br />
{<br />
Console.Out.WriteLine (ex.ToString());<br />
}<br />
}<br />
}<br />
}<br />
|
|
|
|
|
Does anyone know what exactly the term 'static' means in reference to web apps? Does this mean that there is only a single instance of the variable within the DLL itself and everyone who runs an instance of a particular page can modify the variable?
If this is the case then how does one hold values in page level variables and have them maintain there value when the page posts back (for autopostback objects...)?
Thanks in advance for anyone with a good explanation.
~LizardWiz()
|
|
|
|
|
static is static across AppDomains. AFAIK, ASP.NET creates a separate AppDomain for each application and so everyone who runs a particular page must get the same value.
I don't know if ASP.NET will unload appdomains during heavy load and reload them later, if that's true, then your static variables will be gone.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Everyone who runs an instance of a particular page can modify the variable. Each session gets it own copy of shared property.
Sanjay Sansanwal
www.sansanwal.com
|
|
|
|