|
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
|
|
|
|
|
Member 2281771 wrote: C# wrapper for SharpSphinx
Googling suggests that question is odd because that library is a C# library.
The problem though appears to be finding that library.
I used the following to research that and similar should work for your other part
C# SharpSphinx
Or just look at the following or find a different solution.
C# Speech to Text[^]
You can google for other solutions with the following.
C# speech to text
|
|
|
|
|
You are absolutely right, I have 2 problems :
- Where to get SharpSphinx , because i have googles it , but did nto find it. It was hosted by Codeplex, but after Codeplex shutdown, it is not there, even into archive.
- alternative solution is to get PocketSphinx to work with C# , since it is un-managed code (C++), I cannot use the dll.
|
|
|
|
|
I already provided alternatives and I just validated again that they do seem to exist.
|
|
|
|
|
Hi to all.
Did anyone already work on C# wrapper for SharpSphinx or PocketSphinx for converting speech to text
Thanks.
Waleed
|
|
|
|
|
hi
modified 19-Jun-19 0:43am.
|
|
|
|
|
And?
What have you tried?
Where are you stuck?
What help do you need?
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!
|
|
|
|
|
1. First i am trying PDF file drag and drop in the Acrobate PDF properties there is not Event for DragDrop and DragEnter.
Any opensource avaiable? in c#
|
|
|
|
|
That still tells us nothing about what you are trying to do: we have no idea what controls you are trying to use and failing with, let alone how you are trying to use them!
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
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!
|
|
|
|
|
I am Using AcrobatPDF in the AcrobatPDF i have to drag and drop pdf file form my desktop or any other folder. once drag and drop the pdf file in the winforms. After Clicking PDF File it comes in fullscreen.
In AcrobatPDF its possible to drag n and drop PdF document
|
|
|
|
|
This has "long day" written all over it ...
What does that have to do with C#?
What controls are you using?
What - exactly - are you trying to do with them?
Please, remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. Unless you give us information, we can't respond to it - and we have no idea what code you are trying ...
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!
|
|
|
|
|
Go to ParentI am using Windows application Web browser control
1. in my winforms i have 9 webbrowser control each web browser control load all files
eg: image, pdf, word excel
2. now in my winforms webbrowser control loading image when i drag and drop image in webbrowser1 the image size is not expand to webbrowser control window. i write this code for image expand to webbrowser control.
private void webbrowser1_DocumentCompleted(object sender,WebbrowserDocumentCompletedEventArgs e)
{
var img = webBrowser1.Document.GetElementsByTagName("img").Cast<htmlelement>().FirstOrDefault();
var w = img.ClientRectangle.Width;
var h = img.ClientRectangle.Height;
img.Style = string.Format("{0}: 100%", w > h ? "Width" : "Height");
}
after this code is expanding image in webbrowser1 control and preview full screen.
now i am trying to load pdf in Webbrowser1 show error
Object reference not set to an instance of an object.
|
|
|
|