Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

How would I initialize this instance variable reading from a text file or xml file?

 

int SmallRTBResizeH=??FromFile()??; I tried that, it does not work.

 

This is one of the user defined settings in my program.

Is text or xml the best way to go?

C#
  • Leaders
Posted

I do this from an xml config file.

Shared Sub New()
       cnnStr = GetConfig("connectionString")
       strRootDir = GetConfig("rootDir")
       intRecentDefinition = GetConfig("recentDefinition")
       strRootWebDir = GetConfig("rootWebDir")
   End Sub

   Private Shared Function GetConfig(ByVal key As String) As String
       Try
           Dim xmlDoc As New XmlDocument()
           xmlDoc.Load("..\Config.xml")
           Return xmlDoc.GetElementsByTagName(key).Item(0).InnerXml
       Catch ex As Exception
           Throw New Exception("Error reading configuration file: Config.xml", ex)
       End Try
   End Function

--tim
Posted (edited)

I can't quite understand VB. I only know C# and C++ some.

 

I did this and it works but I don't think it is the best way becuase I cannot seem to close the streams but it also does not seem to matter? Can someone reassure me?

 

static StreamReader sR=new StreamReader(house+"\\"+"Settings\\SmallRTBResize.txt");

int SmallRTBResizeH=Int32.Parse(sR.ReadToEnd());

Edited by aewarnick
C#
Posted

I put in the construtor and it works great but I still do not know if that is the best way to do it or not?

 

StreamReader sRTBRH=new StreamReader(house+"\\"+"Settings\\SmallRTBResize.txt");

try

{SmallRTBResizeH=Int32.Parse(sRTBRH.ReadToEnd());} catch{SmallRTBResizeH=136;}

sRTBRH.Close();

C#

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...