Click here to Skip to main content
15,918,268 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralUsing SelectedItem to have pre select item in combo box Pin
AAGTHosting16-Apr-08 8:10
AAGTHosting16-Apr-08 8:10 
GeneralRe: Using SelectedItem to have pre select item in combo box Pin
Dave Kreskowiak16-Apr-08 8:38
mveDave Kreskowiak16-Apr-08 8:38 
QuestionModifying XML Nodes Pin
CocaColaBoy16-Apr-08 6:46
CocaColaBoy16-Apr-08 6:46 
GeneralRe: Modifying XML Nodes Pin
Dave Kreskowiak16-Apr-08 8:41
mveDave Kreskowiak16-Apr-08 8:41 
GeneralRe: Modifying XML Nodes Pin
CocaColaBoy16-Apr-08 8:52
CocaColaBoy16-Apr-08 8:52 
GeneralRe: Modifying XML Nodes Pin
Dave Kreskowiak16-Apr-08 9:23
mveDave Kreskowiak16-Apr-08 9:23 
GeneralRe: Modifying XML Nodes Pin
CocaColaBoy16-Apr-08 10:08
CocaColaBoy16-Apr-08 10:08 
GeneralRe: Modifying XML Nodes Pin
Dave Kreskowiak16-Apr-08 11:06
mveDave Kreskowiak16-Apr-08 11:06 
OK. We'll start with line number 1:

CocaColaBoy wrote:
Dim CurDir As String = Environment.CurrentDirectory() & "\globalConfig.xml"


Bad idea. CurrentDirectory is NOT a static directory. Annyone who's ever just thrown around an OpenFileDialog knows that the current directory can change at any time. A more proper method is to use a well-known folder that doesn't change, like Application.StartupPath. Also, don't use string concatenation to build paths, use something that's designed for the task:
Dim filePath As String = Path.Combine(Application.StartupPath, "globalConfig.xml")


CocaColaBoy wrote:
Dim sr As New System.IO.StreamReader(CurDir)
Dim globalConfig As Xml.XmlDocument = New Xml.XmlDocument()
globalConfig.Load(CurDir)
Dim buildingList As Xml.XmlNodeList
...


Yikes. You're opening a file on the first line of this section, but never using it, nor ever CLOSING it either. This is where your problem originated from. Then, in the next line, you're using the XmlDocument.Load method to grab the contents of the .xml file. You can have two processes (or the same process in this case) both read the same file at the same time, but writing to an already open file usually requires exclusive access to the file. In your case, you've guaranteed that exclusive access is impossible by putting creating the StreamReader instance at the top of your code.


A guide to posting questions on CodeProject[^]



Dave Kreskowiak
Microsoft MVP
Visual Developer - Visual Basic
     2006, 2007, 2008




GeneralRe: Modifying XML Nodes Pin
CocaColaBoy16-Apr-08 11:38
CocaColaBoy16-Apr-08 11:38 
GeneralRe: Modifying XML Nodes Pin
CocaColaBoy16-Apr-08 11:55
CocaColaBoy16-Apr-08 11:55 
GeneralRe: Modifying XML Nodes Pin
Luc Pattyn16-Apr-08 12:13
sitebuilderLuc Pattyn16-Apr-08 12:13 
GeneralRe: Modifying XML Nodes Pin
Dave Kreskowiak17-Apr-08 3:00
mveDave Kreskowiak17-Apr-08 3:00 
QuestionServiceProcessInstaller account? Pin
AHeavey16-Apr-08 5:57
AHeavey16-Apr-08 5:57 
AnswerRe: ServiceProcessInstaller account? Pin
Dave Kreskowiak16-Apr-08 6:37
mveDave Kreskowiak16-Apr-08 6:37 
GeneralRe: ServiceProcessInstaller account? Pin
AHeavey16-Apr-08 6:39
AHeavey16-Apr-08 6:39 
Generalbound combobox... Pin
sabr4916-Apr-08 3:43
sabr4916-Apr-08 3:43 
GeneralRe: bound combobox... Pin
Dave Kreskowiak16-Apr-08 4:13
mveDave Kreskowiak16-Apr-08 4:13 
GeneralRe: bound combobox... Pin
sabr4916-Apr-08 4:54
sabr4916-Apr-08 4:54 
GeneralRe: bound combobox... Pin
Dave Kreskowiak16-Apr-08 8:24
mveDave Kreskowiak16-Apr-08 8:24 
Questionprinting form Pin
asha_s16-Apr-08 0:45
asha_s16-Apr-08 0:45 
GeneralRe: printing form Pin
Zaegra16-Apr-08 1:40
Zaegra16-Apr-08 1:40 
GeneralRe: printing form Pin
asha_s16-Apr-08 6:52
asha_s16-Apr-08 6:52 
GeneralRe: printing form Pin
Steven J Jowett16-Apr-08 4:08
Steven J Jowett16-Apr-08 4:08 
GeneralRe: printing form Pin
asha_s16-Apr-08 6:51
asha_s16-Apr-08 6:51 
GeneralRe: printing form Pin
Steven J Jowett16-Apr-08 12:16
Steven J Jowett16-Apr-08 12:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.