Results 1 to 11 of 11

Thread: file manipulation.

  1. #1

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    file manipulation.

    1. In a button_Click. My application will copy files(.doc,.txt....) from server to client.

    2. User might make some changes in files client side,.

    3. In another event, the file will copy from client to server.

    Prob:
    My users, overwriting an old file in the client side with same file name and saving the file from client to server. How to restrict this??
    Visual Studio.net 2010
    If this post is useful, rate it


  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: file manipulation.

    The Copy method you're using will allow you to specify whether or not to overwrite existing files.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: file manipulation.

    Hey,

    To follow on from what jmcilhinney said, have a look at the following:

    http://msdn.microsoft.com/en-us/library/9706cfs5.aspx

    Hope this helps!!

    Gary

  4. #4

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: file manipulation.

    Quote Originally Posted by jmcilhinney View Post
    The Copy method you're using will allow you to specify whether or not to overwrite existing files.
    no sir, they are ovewriting the file manually in the client side.

    So i cant avoid the user to overwrite the file..

    So if i validate the difference between the modified time? its a correct process,..Any disavantage in this..
    s Code:
    1. Dim sServer As String = "#######\128974_1_En_2_Chapter.xml"
    2.         Dim sClient As String = "C:\Enfocus\Deva\128974_1_En_2_Chapter.xml"
    3.         If File.Exists(sServer) Then
    4.             If File.Exists(sClient) Then File.Delete(sClient)
    5.  
    6.             File.Copy(sServer, sClient)
    7.         End If
    8.         Dim odDate As DateTime = File.GetLastWriteTime(sClient)
    9.         Dim osDate As DateTime = File.GetLastWriteTime(sServer)
    10.  
    11.         'If Date.Compare(osDate, odDate) > 1 Then
    12.         If DateDiff(DateInterval.Second, osDate, odDate)  > 1 Then
    13.             MessageBox.Show("failure-Wrong file")
    14.  
    15.         Else
    16.             MessageBox.Show("Success-Right File")
    17.         End If
    Last edited by vijy; Mar 18th, 2009 at 03:58 AM.
    Visual Studio.net 2010
    If this post is useful, rate it


  5. #5
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: file manipulation.

    Hi. Vijay,
    I am not able to under stand your question.
    Do you mean that if the users places a file with the same name of server and you need to check like the current file is valid file or not using the modified date ?
    Please mark you thread resolved using the Thread Tools as shown

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: file manipulation.

    I read it as they were overwriting the file on the file system and he wanted to use the modified date to see if the version on the client was still the same as the one on the server.

    Would comparing the hash of the files not be a better way of checking for equality?

    Gary

  7. #7

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: file manipulation.

    Quote Originally Posted by danasegarane View Post
    Hi. Vijay,
    I am not able to under stand your question.
    Do you mean that if the users places a file with the same name of server and you need to check like the current file is valid file or not using the modified date ?
    am pasting a file in local working folder(C:\) from server, user pasting old files and saving into server.i want to restrict this..
    Visual Studio.net 2010
    If this post is useful, rate it


  8. #8
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: file manipulation.

    I don't think you can restrict it, as such. You might be able to do something with a FileSystemWatcher, but that would involve having it installed on all clients. I think the better way would be with comparing the files on both the client and server before proceeding.

    Gary

  9. #9
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: file manipulation.

    And may be you could do like save the file contents in a temp file and while saving to server check the differences in file content and do the appropriate action
    Please mark you thread resolved using the Thread Tools as shown

  10. #10

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: file manipulation.

    Quote Originally Posted by gep13 View Post
    I don't think you can restrict it, as such. You might be able to do something with a FileSystemWatcher, but that would involve having it installed on all clients. I think the better way would be with comparing the files on both the client and server before proceeding.

    Gary
    is it possible to restrict copying and pasting files in a particlar folder..? but user can edit the file contents...
    Visual Studio.net 2010
    If this post is useful, rate it


  11. #11
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: file manipulation.

    Hey,

    I don't know of a specific solution, but there be something you can do.

    I am not sure of the exact problem that you having though. What is the difference between them editing a file, and them overwriting one? At the end of the day, they are still editing the file.

    The easiest way would be to restrict their permissions on that folder.

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width