|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid..
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
Hello all,
I am working on on functionality in which i want to write a c# function which will read XML file from folder.
And it will write .txt file from it and will put it in other folder.
can some one help me to do this, when i am reading XML file line by line i should able to write any error or log in log file, if some thing is wrong it should rollback all file else generate .txt file.
Needs to implement it using any design pattern.
|
|
|
|
|
Technically, an XML file is already a text file. All you need to do is change the file extension.
Now, if you actually want to transform the XML in some way, then you're going to need to either write code to do it, or write an XSLT transform[^] to do it.
But since you've provided precisely zero details about the input and expected output, nobody can possibly help you.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
MyPluginDllClass
{
MyClass _myClass {get; set} = new(this);
public MyPluginDllClass
{
}
public void Test1()
{
}
}
public MyClass
{
MyPluginDllClass _instanceMyPluginDllClass;
public MyClass(MyPluginDllClass param)
{
_instanceMyPluginDllClass = param;
}
public void Test2()
{
_instanceMyPluginDllClass.Test1();
}
}
Hello,
for being able to see all properties in the UI of MyPluginDllClass I would have to instantiate MyClass
as shown above in the properties area of MyPluginDllClass as follows:
MyClass _myClass {get; set} = new(this);
But this does not work, "this" seems to be unknown at this moment in time.
The goal is to use all member functions and properties of MyPluginDllClass within MyClass and to make all properties of MyClass visible in the property grid of the UI of the main application.
Any Ideas, hints what I am doing wrong or why this is the case.
I do not have access to the code of the main application.
MyPluginDllClass ist the interface to the main application.
|
|
|
|
|
You can't use new(this) in a property initializer as the initializer would require the whole object to be initialised by that point, and that cannot be the case because the constructor has not been called yet. And obviously, the constructor can't be called until all property and field initializers are complete!
So you would end up with a deadlock: the instance can't be created because to create the instance you need access to the fully constructed instance!
What you can do is move the initializer to the constructor:
public class Bar
{
public Bar(Foo foo) { }
}
public class Foo
{
public Bar bar {get; set;}
public Foo ()
{
bar = new(this);
}
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
While I appreciate all the syntactic shortcuts Anders and friends are giving us in the C# language, I feel it's getting a bit ridiculous. We're quickly approaching a point where the shortcuts are making the code unreadable and harder to understand for noobs in favor of making it faster to type.
I suspect the new shortcut is giving the OP trouble in understanding what's going on.
|
|
|
|
|
I agree - the same thing happened to C++ to the point where it's almost unreadable now.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
LOL. I think that's the primary reason why I don't do C++ anymore. That and someone has to pick up my code and maintain it after I'm gone and it's easier to find a C# dev (or Java dev we can convert) than it is to find a C++ dev for the team I'm on.
|
|
|
|
|
Is there a way to exclusively identify email-enabled public folders using Microsoft.Office.Interop.Outlook? EWS or PowerShell should not be used. The program should run on the workstation and utilize the installed Outlook.
Once I've found an email-enabled public folder, I should list the emails contained within it.
So far, I'm encountering difficulties. For instance, I have the following method:
static void ListPublicFolders(Outlook.Folder? folder, string indent)
{
if (folder != null)
{
foreach (object obj in folder.Folders)
{
if (obj is Outlook.Folder)
{
Outlook.Folder? subFolder = obj as Outlook.Folder;
if (subFolder != null && subFolder.DefaultItemType == Outlook.OlItemType.olMailItem)
{
Outlook.MAPIFolder? parentFolder = subFolder.Parent as Outlook.MAPIFolder;
string parentName = parentFolder != null ? parentFolder.Name : "Parent folder not found";
Console.WriteLine($"{indent}- {subFolder.Name}: {parentName}");
if (parentFolder != null)
{
Marshal.ReleaseComObject(parentFolder);
}
}
ListPublicFolders(subFolder, indent + " ");
if (subFolder != null)
{
Marshal.ReleaseComObject(subFolder);
}
}
}
}
}
The query
if (subFolder != null && subFolder.DefaultItemType == Outlook.OlItemType.olMailItem)
fails because subFolder.DefaultItemType returns the value Outlook.OlItemType.olPostItem, even though the public folder was set up as an email-enabled folder in Exchange.
Specifically, this is in Microsoft 365. In the Exchange admin center, when creating the folder, I explicitly checked the box for "Email-enabled." This action resulted in two additional options: "Delegation" and "Email properties." In "Email properties," I can specify an alias and a display name. By default, both fields are set to "Orders." Now, I expect the public folder to be email-enabled, with the email address orders@domain.tld.
I don't understand why Outlook is treating the folder incorrectly (I can only create posts and not send emails).
Perhaps someone can help me figure this out.
Thank you and best regards,
René
|
|
|
|
|
Hi All,
Stupid Question time. If a value is read to a textbox it is a String, to convert it to a value in the past I have done:
int Value = 0;
Value = Convert.ToInt16(textBox1.Text) I'm sure of it and then done maths and operations on the Value such as:
if(Value > 1000)
{
MessageBox.Show("Here!");
} But it won't run in VS2022 it returns a System.Format.Exception error. What have I done?
Glenn
modified 9-May-24 10:29am.
|
|
|
|
|
Don't use Convert as any error in the format of the input string will cause an exception.
Instead use int.Parse because you can check the result of the parse operation to see if you have entered a valid or invalid string.
From memory you should do the following
if (int.Parse(textBox1.Text, out int result))
{
}
else
{
}
|
|
|
|
|
You mean TryParse ; Parse returns the parsed value or throws an exception.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I checked that twice and still missed that (Doh)
|
|
|
|
|
What value is in the textbox? If it can't be parsed as a short using the current culture settings, then Convert.ToInt16 will throw an exception.
You should use TryParse[^] rather than the Convert method to avoid the "can't parse this" exception:
if (int.TryParse(textBox1.Text, out int value))
{
if (value > 1000)
{
MessageBox.Show("Here!");
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hmmm, I'm reading back a sensor, it's giving values all over the show!
private void button1_Click(object sender, EventArgs e)
{
if (int.TryParse(textBox1.Text, out int value))
{
if (value > 1000)
{
MessageBox.Show("Here!");
}
MessageBox.Show(value.ToString());
}
MessageBox.Show(value.ToString());
}
value is taken as 0, despite textBox1.Text having 1234.56...
|
|
|
|
|
glennPattonWork3 wrote: despite textBox1.Text having 1234.56... But 1234.56 is a Float/Double not an Int ; the two are quite different.
|
|
|
|
|
You are right, but even if make 1234 it still returns a 0...
|
|
|
|
|
Come on Glen, you need to show us the exact code, and the exact text that you are using.
|
|
|
|
|
Hi,
This is the code I have been trying to get all afternoon!
private void button1_Click(object sender, EventArgs e)
{
float ForceVal = 0;
<pre>
decimal.TryParse(weightTxt.Text, out decimal value);
if (value > 1000)
{
MessageBox.Show("Here!");
}
MessageBox.Show(value.ToString());
}
I think that should do it. I'm hacking together a test program that interfaces to a Phidget load cell in trying to measure a value that needs to converted to Newtons from Grams (I think!). I hate the fact I wasted so much time trying to get the value to be used out of a darned label. I haven't really done much Windows code (I'm an embedded guy really) since VS2008 was the new kid on the block and times like these it shows!
|
|
|
|
|
Did the TryParse call succeed, return true?
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Sort of I had to:
decimal.TryParse(weightTxt.Text, out decimal value);
as I was messing with a floating point number, haven't coded in Windows for a while, man it shows!
|
|
|
|
|
Maybe try decimal.TryParse()? as the input is not an int.
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|
|
Thanks, that appears to work!
|
|
|
|
|
Good news!
"the debugger doesn't tell me anything because this code compiles just fine" - random QA comment
"Facebook is where you tell lies to your friends. Twitter is where you tell the truth to strangers." - chriselst
"I don't drink any more... then again, I don't drink any less." - Mike Mullikins uncle
|
|
|
|