locked
Access server folders and files RRS feed

  • Question

  • Using Visual Studio 2005 in vb how do i

     

    Im wriign a stand alone app that will access our server and delete folders based on supplied user name.. what im doing

    is deleteing folders on a citrix server based on user id..

    so how can I:

     

    1. access our server,,, the url is always going to be the same  \\server\.......

    2. once i gain access i need to be able to delete folders on the server ??

     

    sorry its not more explicit but thats the simple question, i cant seem to find anything searching...

     

    Thanks M2M

    Friday, May 30, 2008 1:19 PM

Answers

  • Does this work?

     

    using System.IO;

     

    Directory.Delete( @"\\server\MyFolder");

     

    Friday, May 30, 2008 2:49 PM
  • you are going to have security problems here. you need to make sure that the folder you are trying to access, in order to delete, has the appropriate security permissions for the user account to access, the user account being the account that the appliction is running under.

     

    once this is solved, then you can do this:

     

    Dim username as String = Environment.UserName

    Dim directories() as string = Directory.GetDirectories("\\server\pathToFolder")

     

    for each currentDir as string in directories

     

       if currentDir.Trim().ToLower() = username then

     

         Directory.Delete(currentDir, true) 'this will delete all directories and files within the currentdirectory if the current directory matches the username retrieved

     

       end if

     

    next

    Friday, May 30, 2008 8:00 PM
  • Dim directories() As String = Directory.GetDirectories(FinalPath) 'Get the data after the user presses Start

     

     

    For Each currentDir As String In directories

    If currentDir.Trim().ToLower() = User Then

    Beep()

    End If

    Next

     

    Smile
    Tuesday, June 3, 2008 7:14 PM

All replies

  • Does this work?

     

    using System.IO;

     

    Directory.Delete( @"\\server\MyFolder");

     

    Friday, May 30, 2008 2:49 PM
  •  

    I guess I need some basics first of all how do i access the folders ???  \\server\directory\...????

     

    Friday, May 30, 2008 2:52 PM
  •  

    Sorry i will try to clarify:

    What i need to do is get a user name i.e. "meymit"(i can do this)

    Navigate to the directory on the server \\server\c$\documents and settings

    Now check every folder in there against the user name and if it exists delete it..(folder)

    Also when you do that you always get the dialog box that says are you sure you want to do this , and i need

    to be able to code the equivalent of pressing "Yes to All" button..

     

    Hope this clarifiys better Smile

    Friday, May 30, 2008 7:21 PM
  • you are going to have security problems here. you need to make sure that the folder you are trying to access, in order to delete, has the appropriate security permissions for the user account to access, the user account being the account that the appliction is running under.

     

    once this is solved, then you can do this:

     

    Dim username as String = Environment.UserName

    Dim directories() as string = Directory.GetDirectories("\\server\pathToFolder")

     

    for each currentDir as string in directories

     

       if currentDir.Trim().ToLower() = username then

     

         Directory.Delete(currentDir, true) 'this will delete all directories and files within the currentdirectory if the current directory matches the username retrieved

     

       end if

     

    next

    Friday, May 30, 2008 8:00 PM
  •  

    Thanks You:

    I have a question however,,, if i am administrator and have admin rights, i can access the servers from my pc if

    i run this application it should also have rights to access servers correct??

    Anyway here is my code snippet, note that what i am doing is needing to loop through 6 cittrix servers, match on

    user name and then erase directories matching thier name...

    could you help on the next steps please i just need a little push here;;

     

     

    Private Sub Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click

    Dim Citrix As String

    Dim Number As Integer

    Dim User As String = Environment.UserDomainName

    Dim FinalPath As String

    Dim EndPath As String = "\c$\Document and Settings\"

    Dim Wrap As String = Chr(13) & Chr(10)

    Dim directories() As String = Directory.GetDirectories("\\server\mis.")

     

    'Get the data after the user presses Start

    Number = ComboBox2.Text

    User = UCase$(TextBox1.Text) 'Make user name uppercase

    Citrix = ComboBox1.Text

    Dim Path As String = ComboBox1.Text

    FinalPath = "\\" & Citrix & Number & EndPath

    Start.Visible = False

    Cancel.Visible = False

    SmoothProgressBar1.Visible = True

    Finish.Visible = True

    Me.SmoothProgressBar1.Value = 1

     

     

     

     

     

    TextBox2.Text = "User: " & User & Wrap

    TextBox2.Text = TextBox2.Text & " Had " & "Profiles" & Wrap

    TextBox2.Text = TextBox2.Text & " On Citrix Servers"

     

     

    Me.Timer1.Interval = 1

    Me.Timer1.Enabled = True

    Me.SmoothProgressBar1.UseWaitCursor = False

    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    If (Me.SmoothProgressBar1.Value > 0) Then

    Me.SmoothProgressBar1.Value += 1

    TextBox3.Text = SmoothProgressBar1.Value

    Else

    Me.Timer1.Enabled = False

    End If

    End Sub

    Monday, June 2, 2008 12:47 PM
  • I keep getting two errors with this code:

    directories()

    1.value of string cannot be converterd to  1 dementional array

    2.Trim is not amember of system.array

     

     

    Private Sub Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click

    Dim Citrix As String

    Dim Number As Integer

    Dim User As String = Environment.UserDomainName

    Dim FinalPath As String

    Dim Path As String = ComboBox1.Text

    Dim EndPath As String = "\c$\Documents and Settings\"

    Dim Wrap As String = Chr(13) & Chr(10)

    Number = ComboBox2.Text

    User = UCase$(TextBox1.Text) 'Make user name uppercase

    Citrix = ComboBox1.Text

    FinalPath = "\\" & Citrix & Number & EndPath

    Dim directories() As String = Directory.GetDirectories(FinalPath) 'Get the data after the user presses Start

     

     

    For Each currentDir() As String In directories

    If currentDir.Trim().ToLower() = User Then

    Beep()

    End If

    Next

     

     

     

    Start.Visible = False

    Cancel.Visible = False

    SmoothProgressBar1.Visible = True

    Finish.Visible = True

    Me.SmoothProgressBar1.Value = 1

     

     

     

     

     

    TextBox2.Text = "User: " & User & Wrap

    TextBox2.Text = TextBox2.Text & " Had " & "Profiles" & Wrap

    TextBox2.Text = TextBox2.Text & " On Citrix Servers"

     

     

    Me.Timer1.Interval = 1

    Me.Timer1.Enabled = True

    Me.SmoothProgressBar1.UseWaitCursor = False

    End Sub

    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick

    If (Me.SmoothProgressBar1.Value > 0) Then

    Me.SmoothProgressBar1.Value += 1

    TextBox3.Text = SmoothProgressBar1.Value

    Else

    Me.Timer1.Enabled = False

    End If

    End Sub

    Private Sub SmoothProgressBar1_BindingContextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles SmoothProgressBar1.BindingContextChanged

    End Sub

    Private Sub SmoothProgressBar1_FontChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles SmoothProgressBar1.FontChanged

    End Sub

    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged

    End Sub

    Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    End Class

    Monday, June 2, 2008 1:48 PM
  • Dim directories() As String = Directory.GetDirectories(FinalPath) 'Get the data after the user presses Start

     

     

    For Each currentDir As String In directories

    If currentDir.Trim().ToLower() = User Then

    Beep()

    End If

    Next

     

    Smile
    Tuesday, June 3, 2008 7:14 PM