Results 1 to 10 of 10

Thread: [RESOLVED] File extended attributes

  1. #1

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    784

    Resolved [RESOLVED] File extended attributes

    I need to find the username and computer name of a user who uploads a file to the server.
    The articles I have read are not clear and uses the Shell.Application, but I could not implement it.
    Extended properties are not listed under the filesystemobject.

    Thanks
    PK

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: File extended attributes

    while shell automation will get some additional attributes from file in a folder, it would be the folder they currently reside in, i doubt there is any property that will indicate the original user or computer

    you can try like
    Code:
    Set sh = CreateObject("shell.application")
    Set n = sh.Namespace("c:\temp")
    Set f = n.parsename("order.HTML")
    For i = 0 To 34
        Debug.Print n.getdetailsof(f, i)
    Next
    to see if you get any useful information, change folder and filename to suit, you can also loop all items in the folder if that is helpful, if you want to use early binding add a reference to shell automation and change your variable from object to appropriate type
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    784

    Re: File extended attributes

    Thanks westconn1,
    What is the name of the shell reference? I do not seem to have it in my available reference list.

    PK

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: File extended attributes

    microsoft shell controls and automation

    or browse for c:\windows\syswow64\shell32.dll
    but i have never not seen it in the list of available references
    Last edited by westconn1; Oct 4th, 2019 at 02:43 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    784

    Re: File extended attributes

    I am still struggling with getting the file set. In the code, the last code line does not work:

    Code:
    Dim FilePath As String
    Dim fso As New FileSystemObject
    Dim File As File
    Dim objShell As Shell32.Shell
    Dim NSpace As Folder
    Dim FileName As String
     
    
           FilePath = Left(cdlFile.FileName, LastBackSlash - 1)
            FileName = Right(cdlFile.FileName, Len(cdlFile.FileName) - LastBackSlash)
            Set NSpace = objShell.NameSpace(FilePath)
            Set File = NSpace.Files(FileName)
    PK

  6. #6
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: File extended attributes

    If you are at the server I'm not sure where you expect to get "source user and machine name" from. You never said what "upload" means either. FTP? HTTP? A file share and Microsoft Networking?

    And at the user's end they can obtain that information far more easily to send it to the server.

    It feels like you have gone way off the rails here.


    Even if you really did want extended properties of a file (which don't include the info you are after) the GetDetailsOf() method is not the way to go.

    Example:

    Code:
        Const ssfDESKTOP = 0
        Dim Prop As Variant
        Dim Msg As String
    
        With CreateObject("Shell.Application").NameSpace(ssfDESKTOP)
            'Must use full path here:
            With .ParseName(App.Path & "\Lorem.docx")
                Msg = "Title: "
                Prop = .ExtendedProperty("System.Title")
                If IsEmpty(Prop) Then
                    Msg = Msg & "n/a" & vbNewLine
                Else
                    Msg = Msg & Prop & vbNewLine
                End If
        
                Msg = Msg & "Template: "
                Prop = .ExtendedProperty("System.Document.Template")
                If IsEmpty(Prop) Then
                    Msg = Msg & "n/a" & vbNewLine
                Else
                    Msg = Msg & Prop & vbNewLine
                End If
        
                Msg = Msg & "Author: "
                Prop = .ExtendedProperty("System.Author")
                If IsEmpty(Prop) Then
                    Msg = Msg & "n/a" & vbNewLine
                Else
                    Msg = Msg & Join$(Prop, ", ") & vbNewLine
                End If
        
                Msg = Msg & "Word count: "
                Prop = .ExtendedProperty("System.Document.WordCount")
                If IsEmpty(Prop) Then
                    Msg = Msg & "n/a" & vbNewLine
                Else
                    Msg = Msg & Format$(Prop, "#,##0") & vbNewLine
                End If
        
                Msg = Msg & "Character count: "
                Prop = .ExtendedProperty("System.Document.CharacterCount")
                If IsEmpty(Prop) Then
                    Msg = Msg & "n/a" & vbNewLine
                Else
                    Msg = Msg & Format$(Prop, "#,##0") & vbNewLine
                End If
            End With
        End With
        MsgBox Msg
    ExtendedProperty keys are defined in the propkey.h C header file in the Windows SDK. If you don't have a recent SDK you should really get one.

    https://developer.microsoft.com/en-U...windows-10-sdk

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    24,482

    Re: File extended attributes

    I have no idea what sent you down the FSO rabbit hole either. It doesn't really offer anything useful to a VB6 programmer aside from maybe a simple way to do Unicode text I/O.

  8. #8

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    784

    Re: File extended attributes

    The process under discussion is the upload of files from a user's PC via HTTP with RPC to a server as per my application. I need to gather information like file size, author, PC username, PC name and so on from the user PC to send to the server and store it there in a registry, otherwise it is lost. That information is necessary so that I can know what the origin of the file is.

    PK

  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: File extended attributes

    I need to gather information like file size, author, PC username, PC name and so on from the user PC to send to the server
    you should be getting this information before or when the files are uploaded, once they are uploaded the information is no longer retained with the file

    depending on the method used to upload the files it may be possible to catch some of this information during the upload process


    the last code line does not work:
    you can not return the datails as a collection, though you could add all the details to a collection, you have to loop through all the properties, so the last line should look like
    Code:
    debug.print NSpace.getdetailsof(FileName, x)
    where x is a number between 0 and 34, as per the loop in the sample code above
    i do not believe that the line above that would work correctly for your purpose either, it must return a shell file object, else that line would still error

    if you want details for all files in the folder, you should loop through all the folder items like
    Code:
    for each file in nspace.items
    then loop the properties, to store all the properties for all the files into your database, but i still do not think you will get the information you want

    a possible scenario is to have all users upload to specific folder, or filename prefix or suffix ID of some sort, but that may take a very significant amount of user training (possibly with a big stick)

    also you should avoid using reserved words or names of objects (eg file) for variable names
    Last edited by westconn1; Oct 4th, 2019 at 07:22 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10

    Thread Starter
    Fanatic Member Peekay's Avatar
    Join Date
    Sep 2006
    Location
    Witbank, South Africa
    Posts
    784

    Re: File extended attributes

    dilettante,

    Excellent as always. Thanks!
    PK

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