|
Member 14506843 wrote: Can anyone please help me?
Ok
1. Learn the basics of programming in one language
2. Learn the basics of socket programming in that language
3. Learn the basics of UI programming in that language.
4. Put 1-3 together to create application one.
5. Put 1-3 together to create application two.
|
|
|
|
|
pls help me.
How to create a chat application in Website that users chat privately with administrator and administrators can see many users using c# mvc.
pls help me. thank all pro
|
|
|
|
|
|
mvc chat application - Google Search[^]
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
206/5000
Hello everyone ,
I am trying to retrieve XML information, I managed to recover the attributes against the childrens they are not recovering below my code and the form of my XML file:
XML template :
<?xml version="1.0" encoding="utf-8"?>
<Root>
<ToolsList>
<Tool PartNumber="0018B">
<ToolLine Text=" FI : 3897" />
<ToolLine Text=" PINCE1 Reference : M 22520/2.01" />
<ToolLine Text=" Position : 2.02" />
<ToolLine Text=" Reglage : 7" />
<ToolLine Text=" PINCE2 Reference: M 22520/7.01" />
</Tool>
</ToolsList>
</Root>
Code C#:
Imports System.IO
Imports System.Xml
Module ParsingUsingXmlDocument
Sub Main()
Try
Dim m_xmld As XmlDocument
Dim m_nodelist As XmlNodeList
Dim m_node As XmlNode
'Create the XML Document
m_xmld = New XmlDocument()
'Load the Xml file
m_xmld.Load("D:\Users\Desktop\Xml to excel chahine\U881A1013_105_A_PREP_1.xml")
m_nodelist = m_xmld.SelectNodes("/Root/ToolsList/PartNumber")
'Loop through the nodes
For Each m_node In m_nodelist
Dim partnumber = m_node.Attributes.GetNamedItem("PartNumber").Value
'Get the firstName Element Value
Dim text1 = m_node.ChildNodes.Item(0).InnerText
Dim text2 = m_node.ChildNodes.Item(1).InnerText
Dim text3 = m_node.ChildNodes.Item(2).InnerText
Dim text4 = m_node.ChildNodes.Item(3).InnerText
Console.Write("partnumber: " & partnumber _
& " text1: " & text1 & " text3: " _
& text3)
Console.Write(vbCrLf)
Next
Catch errorVariable As Exception
'Error trapping
Console.Write(errorVariable.ToString())
End Try
End Sub
End Module
if you have any ideas do not hesitate to help me, thanks in advance
after a question how can I implement this information on an excel file
|
|
|
|
|
That isn't C# - that's VB code.
Take it to the right forum: Visual Basic Discussion Boards[^]
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
This has been around like forever: the only solution I know is to explicitly delete the file before each write.
Even though you try and make sure the 'stream is closed using something like:
try
{
using (Stream stream1 = new FileStream(path1, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
{
dcs1.WriteObject(stream1, this.TheData1);
stream1.Position = 0L;
stream1.Close();
}
}
catch (Exception ex)
{
MessageBox.Show($"{path1} in use");
return;
} That can lead to the dread message: "The data at the root level is invalid. Line 1, position 1." after multiple writes: even though careful scrutiny of the XML content of multiple writes shows no special characters inserted, no structural differences, in the files written.
Of course, I would be chuffed to know there is another way !
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
modified 19-Jun-19 18:07pm.
|
|
|
|
|
Why are you using FileMode.OpenOrCreate, FileAccess.ReadWrite rather than FileMode.Create, FileAccess.Write ? The former suggest you will be accessing an existing file and manipulating it in some way that may leave existing data inside.
|
|
|
|
|
A search on "The data at the root level is invalid. Line 1, position 1." will show you what a long history this bug has had.
The code shown is the serialize code that causes errors in deserialization. And, if the file does not exist, I do want it to be created.
Those (future) read errors (after more writes to the same file) can be prevented by deleting the file in the serializer prior to writing:
if (File.Exists(path1))
{
File.Delete(path1);
} Excerpt from deserialization code:
try
{
using (Stream stream1 = new FileStream(path1, FileMode.Open, FileAccess.Read))
{
stream1.Position = 0L;
TheData1 = (Data1) dcs1.ReadObject(stream1);
}
}
catch (Exception ex)
{
MessageBox.Show($"{path1} cannot be read");
return;
} I trust you (if not you, who ?) to have further insights
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
|
I believe the careful comparison of a sequence of multiple writes I carried out, the result of which showed no change in XML content, or structure ... obviates the error you describe, which I am familiar with.
I use 'OpenOrCreate because it does exactly what the name applies.
Next ?
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
I don't have time right now, but would like to revisit this myself sometime. What is the definition of your dcs1 object?
|
|
|
|
|
Hi, always delighted to see your keen mind at work !
[DataContract]
public class Data1
{
public Data1(string id)
{
ID = id;
}
[DataMember]
public string ID { set; get; }
}
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
I just hope it can do something to help.
|
|
|
|
|
BillWoodruff wrote: And, if the file does not exist, I do want it to be created.
I think the FileMode enum[^] values could have been named better.
OpenOrCreate - If the file doesn't exist, create it.
- If it does exist, do not truncate it.
Create - If the file doesn't exist, create it.
- If it does exists, truncate it.
I suspect you want FileMode.Create instead of FileMode.OpenOrCreate .
However, note the warning on the Create option:
"If the file already exists but is a hidden file, an UnauthorizedAccessException exception is thrown."
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
modified 19-Jun-19 11:00am.
|
|
|
|
|
Please note that the statement about my observations of the actual bytes of multiple writes using 'OpenOrCreate would have to reflect hallucinations if what you suggest is correct
fyi: the test project is compiled in VS2017 against 4.5.
The behavior triggered by 'OpenOrCreate has been consistent for years. Maybe we are reading different docs in a parallel universe: [^] Quote: OpenOrCreate Specifies that the operating system should open a file if it exists; otherwise, a new file should be created. If the file is opened with FileAccess.Read, FileIOPermissionAccess.Read permission is required. If the file access isFileAccess.Write, FileIOPermissionAccess.Write permission is required. If the file is opened withFileAccess.ReadWrite, both FileIOPermissionAccess.Read and FileIOPermissionAccess.Write permissions are required. Next ?
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Just goes to show how confusing the names are.
I've just tested it, and the problem is not that OpenOrCreate is appending to the file; it's that OpenOrCreate doesn't truncate the file.
If the new content you write to the file isn't as long as the existing content, you'll end up with the last part of the existing content left at the end. For serialization, this will obviously cause it to break.
Eg:
using (var s = File.Open(path, FileMode.OpenOrCreate))
using (var w = new StreamWriter(s))
{
w.Write("0123456789");
w.Flush();
}
using (var s = File.Open(path, FileMode.OpenOrCreate))
using (var w = new StreamWriter(s))
{
w.Write("ABC");
w.Flush();
}
Using FileMode.Create will truncate the file if it already exists, so you won't see this problem.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
If I had a hat, it would be "off" to you, Sir.
You have identified the critical behavior here. I am surprised that in my extensive googling on this topic, I did not see a mention of the "truncated effect;" however, that MsDN docs don't mention it ... sadly ... is not a surprise.
I make a deep "wai" (Thai gesture of respect) towards the west in your honor.
cheers, Bill
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
BillWoodruff wrote: however, that MsDN docs don't mention it ... sadly ... is not a surprise. The documentation is quite clear about what OpenOrCreate does:
Quote: Specifies that the operating system should open a file if it exists; otherwise, a new file should be created.
|
|
|
|
|
I do appreciate your pointing to the FileMode enum values in your earlier posts ! If I hadn't been convinced I had compared the sequence of file writes rigorously, I would have spotted an extra angle-bracket Use of only one eye is a poor excuse Richard MacCutchan wrote: The documentation is quite clear Yes, but, that does not mention the "truncate" behavior.
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Why would it? That mode does not truncate the file.
|
|
|
|
|
using (Stream stream1 = new FileStream(path1, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
{
dcs1.WriteObject(stream1, this.TheData1);
stream1.Position = 0L;
stream1.Close();
}
Isn't this just adding to the end of any file you already have? Potentially leading to multiple root xml elements? See if putting the Position = 0 before the WriteObject works.
using (Stream stream1 = new FileStream(path1, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None))
{
stream1.Position = 0L;
dcs1.WriteObject(stream1, this.TheData1);
stream1.Close();
}
|
|
|
|
|
Hi, Allocation of a new FileStream in a 'Using statement does result in 'Position == 0.
I do not observe that using 'OpenOrCreate results in appending to the file; afaik: to append requires 'FileMode.Append
cheers, Bill
«Where is the Life we have lost in living? Where is the wisdom we have lost in knowledge? Where is the knowledge we have lost in information?» T. S. Elliot
|
|
|
|
|
Use File.Replace().
That's assuming one can see the possibility that there is more than one way to get somewhere and bothers to try.
I'd rate the problem definition on a par with "Q and A".
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
|
|
|
|
|
Hi to all.
Did anyone already work on C# wrapper for SharpSphinx or PocketSphinx for converting speech to text
Thanks.
Waleed
|
|
|
|