15,911,762 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by AAB40 (Top 40 by date)
AAB40
30-May-17 13:58pm
View
Sorry sir, but this is what the macro recorded for me, thus a possible coding presented by Office. I don't have the time to learn VBA by heart. I am though looking on the internet to get my puzzle together. If you don't have time for this, thank you for your time already and no problem.
AAB40
30-May-17 7:24am
View
I have deleted the improvement as it gives me another runtime error. the solution maciej gave doesn't work for me. I will open a new thread.
AAB40
30-May-17 7:12am
View
Deleted
ppolymorphe: I've closed this issue and opened another one.
AAB40
30-May-17 6:44am
View
Maciej, I have changed my code a bit but now I have a "runtime error 1004: Select method of Range class failed". Your suggestion not to use the 's' didn't work for me. I have edited the code above. Could you have a look please? Know that I first recorded my actions with macro recording and copied-pasted this code in my ActiveX button.
AAB40
29-May-17 12:04pm
View
thank you Maciej. I will have a look tomorrow ;-)
AAB40
29-May-17 11:59am
View
Hi Maciej, no it has nothing to do with my previous question (I think). this question is about the fact that I'm able to add an xmlfile in my current vbaproject in Workbook1, but each time that I click the 'Add an Xml-file' an extra book is added in this current workbook. As in my previous question it was just about staying in the current workbook and not Always opening another one. I'm not opening another workbook anymore, I have my xml- file inserted in my current workbook but in the project the code still adds the other workbooks. As If you would do it manually. You understand this? (In previous post I had someone being very particular with this and actually enoying, expecting for me that I cut down the questions to the bones to be able to go step by step or something like that.)
AAB40
19-May-17 8:12am
View
thank you.
AAB40
9-Mar-17 11:28am
View
Because I need the innertext changed for those nodes. How do you suggest to do so please?
AAB40
2-Mar-17 5:35am
View
Why was this one deleted please? I had a problem, someone helped med and I found a solution.....! ???
AAB40
2-Mar-17 4:16am
View
Deleted
Richard, you want me to update the "What I have tried" or you want me to put it in comment?
AAB40
1-Mar-17 12:00pm
View
Richard, I have edited the code to what I have now. after debugging I see that it's not working.
AAB40
1-Mar-17 9:02am
View
it's not my directory! is a copied example of the mandatory string in the example of the one who posted this.
AAB40
1-Mar-17 9:00am
View
No idea how I should do this in my current code (edited post)
AAB40
1-Mar-17 8:48am
View
Ok, Apparently I'm very bad in expressing myself. Trying again:
User clicks on button "GetFile". Behind the button I have the code for the OpenFileDialog. The filedialog opens the directory where the user can choose a file. The content of the file will open in a RTB.
After changing anything in it, the user wants to save with the same original name + " NEG" behind it, prefilled in the SaveFileDialog. how can I do this please?
AAB40
28-Feb-17 8:27am
View
Jochen, I think it is time that all persons on CodeProject talk to each other to find a good solution on what to do and not to do. In the previous thread I was asked by Karthik to update the issue if I changed something. Not to each time open a new thread that looks like a repost, and they all will look like a repost. Because it's been 5 years that I have used C sharp and I was never a programmer, so everything that I will ask will look at each other. But trying.... Thanks for your time!
AAB40
28-Feb-17 7:45am
View
Improved the code.
AAB40
28-Feb-17 7:29am
View
hello Jochen, yes it is indeed the content of a richtextbox that needs to be read and that should be an xml file. I can't add a string name of the file as it is already in the richtextbox. :-( So actually I'm turning arround not finding any solution to what I want to do.?
AAB40
23-Feb-17 11:02am
View
"You're also saving the wrong thing at the wrong time. You're updating the XML document, but you're trying to save the original text from the RichTextBox, which will not reflect the changes you have made. And you're trying to save that file each time you modify a node, rather than when you've finished updating the document.
Move the code that saves the file outside of the loop:"
Finally a descend answer. Thank you Richard! but
I DON'T WANT TO SAVE TO A PATH FILE ON MY HARDDRIVE! I WANT THE CHANGES TO REFLECT IN THE RICHTEXTBOX PLEASE!!!!!
There HAS to be a solution for that! What? using a streamreader? using a memorystream??? what? How? And Ok, I get it that it's not possible to load an xml in the save of the XmlDocument. Now, you have given me a descend answer about the sequence already, please give me something to work with for the rest..... thanks in advance [^]
AAB40
23-Feb-17 9:36am
View
Might you give me a possible solution you should not have to shout! But before doing so READ what I have updated please! So actually: everything.
AAB40
21-Feb-17 3:56am
View
Richard, I have updated the code according the xml file for better reading and updated the code. But the save failed. could you have a second look please?
AAB40
20-Feb-17 12:14pm
View
Hello Richard, thanks for yoour answer. true, I don't understand how to call the path as in this case there are 2 possibilities: eather I let the user choose the name of the file and save it somewhere in his directory on his harddrive, or otherwise I'm choosing a rootplace on the users driver to save the document and add '-NEG' automatically to the saved file. the filename should be at last the same as the chosen file.
concerning the slashes: I have read that single slahes makes the path to the attributes/nodes static as the double slashes makes them dynamic, meaning that you can find the attribute/node all over the XML document. And that's what I'm searching for. I'm gonna have a look at this tommorrow. Thanks already.
AAB40
17-Feb-17 9:54am
View
Ramza, thanks for your time, but I found where the issue came from. So another issue is popping up now. I have edited the describtion. Could you have a look please?
AAB40
17-Feb-17 8:26am
View
that's what I have done here! It was on behalve of Richard that I wanted the other question closed and start over again here.
AAB40
17-Feb-17 6:22am
View
your solution is still not working. Still have an issue with XmlTextReader that sees strange characters. i don't understand. Is there maybe something I need to add to the references or using systems?
AAB40
17-Feb-17 6:20am
View
richard, I have put another title on it not to mix up the minds of the readers. My question still remains!!!: how can I read the content of an XML file that was openend in a richtextbox? Because THAT is the issue we've stumbled on and the thing you couldn't tell me. Of course I need to put the original issue at hand otherwise the one reading this will not understand or give me a false solution!.
AAB40
17-Feb-17 6:18am
View
the xml file is created according W3school scheme. so no strange characters in it! the only thing is that the xml file starts with " <?xml version="1.0"?> " and that some child tags have attributes. That's all.
AAB40
17-Feb-17 5:18am
View
The exception error is caused by an invalid processing instruction. For example, the processing instruction may contain extraneous spaces. The following is an example of an invalid processing instruction:
<?xml version='1.0' ?> Ref. https://support.microsoft.com/en-us/help/307548/how-to-read-xml-from-a-file-by-using-visual-c. So actually I think it's a good idea to loop against invalid chars. And yes, I added the original code to show the issue.
AAB40
16-Feb-17 11:01am
View
Ramza, I don't have published the whole xmlfile! it's just a part as it is too long to post. the SelectSingleNodes DO exist! ;-). but your 'input' will not change anything as it still will be the string of my richtextbox. Changing my variable name will not change the error. it still gives me the 'Illegal characters in path.' error
AAB40
16-Feb-17 10:51am
View
Hello Ramza, 1) yes my beginning text in the richtTextBox is just like the xml file. 2) I already have tried to change "doc.Load" into "doc.LoadXml" but I'm still having an error further away. 3) where do I get the "input" that you're suggestingf? apparently if I use
string selectedFile = richTextBox1.Text;
it won't generate correctly and give me the first error. So what do you mean with input please?
AAB40
16-Feb-17 8:16am
View
Jochen, I have changed my code to modify the file as thus:
//Read selected file
string selectedFile = @"C:\Users\decraiec\Documents\Visual Studio 2015\Projects\XML testversion.xml";
XmlDocument doc = new XmlDocument();
doc.Load(selectedFile);
//find the node to change the content
//if node is not present, do nothing
foreach (XmlNode xNode in doc)
{
if (xNode.ParentNode.Attributes["*.*"].Value != "") ==> error
{
doc.SelectSingleNode("Identification").InnerText = "string";
doc.SelectSingleNode("SCI").InnerText = "string";
doc.SelectSingleNode("ReferenceType").InnerText = "string";
doc.SelectSingleNode("CCType").InnerText = "AA";
}
else { } //do nothing
}
and now the app is saying that "the object is not set to an instance ...." on line
if (xNode.ParentNode.Attributes["*.*"].Value != "").
AAB40
16-Feb-17 6:34am
View
ow... I think we are misunderstanding each other Jochen. the purpose is to automatically make all positive xml-files negative. So the title should stay the same + "-NEG" at the end. A few internal texts from nodes from the file that I've loaded should change automatically (with the help of the code). So I can't use a descent file name as the title is each time different, each time with each xml-file I choose.
AAB40
16-Feb-17 6:22am
View
Jochen, I already did that. That's where I got the error message about the first line:
//Read selected file
string selectedFile = openFileDialog1.FileName;
XmlDocument doc = new XmlDocument();
doc.LoadXml(selectedFile);
//find the node to change the content
//if node is not present, do nothing
foreach (XmlNode xNode in doc)
{
if (xNode.ParentNode.Attributes["*.*"].Value != "")
{
doc.SelectSingleNode("Identification").InnerText = "string";
doc.SelectSingleNode("ServiceComponentIdentification").InnerText = "string";
doc.SelectSingleNode("ReferenceType").InnerText = "string";
doc.SelectSingleNode("CostCategoryType").InnerText = "AA";
}
else { } //do nothing
}
AAB40
16-Feb-17 6:00am
View
ah OK, thanks. Now, still tumbling over doc.LoadXml(selectedFile); but this time it's saying that the first line of my XML isn't right if I understand it correctly: "Data at the root level is invalid. Line 1, position 1." My xml file starts with "<?xml version="1.0"?>". I remember reading this somewhere but can't find it anymore. do you have an idea please?
AAB40
16-Feb-17 5:55am
View
thank you CPallini
AAB40
16-Feb-17 5:40am
View
Hi F-ES, thanks for your solution that works to pass that line of code but now c sharp is telling me that I should use 'new' for the XmlNode. FYI: I have changed my code a bit meanwhile.
doc.LoadXml(selectedFile);
//find the node to change the content
//if node is not present, do nothing
foreach (XmlNode xNode in doc)
{
if (xNode.ParentNode.Attributes["*.*"].Value != "")
{
doc.SelectSingleNode("Identification").InnerText = "string";
doc.SelectSingleNode("ServiceComponentIdentification").InnerText = "string";
doc.SelectSingleNode("ReferenceType").InnerText = "string";
doc.SelectSingleNode("CostCategoryType").InnerText = "AA";
}
else { } //do nothing
}
AAB40
16-Feb-17 5:07am
View
hello Jochen, I need the content of the xml file, not the title of the xml file nor the header. It's about reading the content of the file that I have selected and change some content in it. How do you figure out that it's the file name from the RichtText control that I'm getting please? Because I don't see it anywhere in the error message.???
AAB40
14-Feb-17 6:45am
View
Richard, I've found the way. Thanks for your time.
AAB40
14-Feb-17 6:35am
View
Hi RyanDev, thanks but I've tried that already and the list of references that we can add is very long without specific other 'xml' additives. the only one that's in there is the one I already have: "using System.Xml;". But nevertheless, if I follow the way of thinking of Richard, I won't need this anymore (I think). Thanks for answering.
AAB40
14-Feb-17 6:33am
View
thanks Richard, that was the easy part, using OpenFileDialog. But it's just writing the title that the user is selecting in the richTextBox, not showing the XML content. Therefore I need something like a reader for the xml file. So first, where should I put the code? within the if-loop or outside? secondly, I don't have specific nodes that I want to change for the moment, it's just reading the XML file and show it completely in the textbox.
AAB40
13-Feb-17 11:42am
View
Thank you Richard for this quick answer. But how do you suggest to do this? As the user needs to select a particular file out of the list before editing it? that are 2 actions instead of 1. Select de file with the cursor and click the 'Edit' button. The "btnGetFiles_Click" only shows a list of all files retrieved from the main folder....
Show More