Advertisement

05.16.2007 at 10:13AM PDT, ID: 22576218
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.8

Have StreamWriter write to the same location the StreamReader is on

Asked by Atropa in Microsoft Visual Basic.Net

Tags: , , ,

I am writing a little app that opens up a logon script using a StreamReader and populates various controls such as text boxes and check boxes etc based on the values in the script.  I can get it to read properly and all is wonderful with it thus far.

The problem comes when I want to save the bloody thing.  I need to be able to write a value into the script in the same location that is in and I don't want to rewrite the ~ENTIRE~ script as well.  

I know one option would be to place the entire contents of the script into a vaiable, replace the text in question with new text then create a new file overwritting the old etc.  I don't want to do that if I can avoid it (Though I am exploring this path as well).

What I was doing is reading in the script again, line by line. When I get to a line that I know ~could~ be modified I check to see if it was changed through the UI and if it was, I want to overwrite the line with the new text.  Below is a sample of what I have thus far in code, but the text is getting written in the wrong location in my script, a sample of the script is further below.  What I was hoping I could somehow do is if I am reading a specific line, I want the writer to write directly to it, replacing the current text.  It seems that I should be using something other than a StreamReader and StreamWriter but I can't think of anything else.  I appreciate all the help in advance!

        Dim FS As FileStream = New FileStream(tScriptName.Text, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)
        Using StreamReader As StreamReader = New StreamReader(FS)
            Dim sLine As String
            Do
                sLine = StreamReader.ReadLine
                If sLine.Contains("aSN                = Array(") = True Then
                    If bServerName = True Then      ' Name Change Only
                        Dim snTemp As String = "   aSN                = Array(" & String.Join(",", SNArray) & ")"
                        Using SW As StreamWriter = New StreamWriter(FS)
                            SW.WriteLine(snTemp)
                        End Using
                    End If
                ElseIf sLine.Contains("' End") Then
                    Beep()
                End If
            Loop Until sLine = "' End"
        End Using
        FS.Close()

Here is also a sample of the logon script:

   aOU                = Array("ou=torrance", "ou=irvine")
   aSN                = Array("\\CLS3", "\\irvinesvr\")      
   sDS               = "developer6"      ' Share Name

' Commands
   Call AdminPwd()      
   Call MapDrives()
   Call LogonScripts()
   Call CheckNAV()Start Free Trial
[+][-]05.16.2007 at 10:43AM PDT, ID: 19102731

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual Basic.Net
Tags: streamwriter, streamreader, file, write
Sign Up Now!
Solution Provided By: Idle_Mind
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.16.2007 at 11:24AM PDT, ID: 19103031

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.16.2007 at 11:32AM PDT, ID: 19103106

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32