0

i have routine for store somes documents into one directory wich run on local drive but get error with network drive if i use path as this "\\172.16.3.145\Directory".

i use this code for create subdirectory needed:

If My.Computer.FileSystem.DirectoryExists(PercorsoDocumenti) = False Then
            My.Computer.FileSystem.CreateDirectory(PercorsoDocumenti)
        End If

        If My.Computer.FileSystem.DirectoryExists(PercorsoOrdini) = False Then
            My.Computer.FileSystem.CreateDirectory(PercorsoOrdini)
        End If

        '+++ creazione della sottodirectory per l'ordine che deve sempre esistere per poter consultare i files presenti +++
        If My.Computer.FileSystem.DirectoryExists(PercorsoOrdini & lblIdOrdinePassato.Text) = False Then
            My.Computer.FileSystem.CreateDirectory(PercorsoOrdini & lblIdOrdinePassato.Text)
        End If

        LstViewDocumentiCaricati.Clear()
        For Each fileName As String In IO.Directory.GetFiles(PercorsoOrdini & lblIdOrdinePassato.Text)
            ImgLstFiles.Images.Add(Icon.ExtractAssociatedIcon(fileName))
            LstViewDocumentiCaricati.Items.Add(IO.Path.GetFileName(fileName), ImgLstFiles.Images.Count - 1)
        Next

This code work and create directory also in path as "\\server\directory" but get error when i try to list all files in a listview with this other code:

For Each fileName As String In IO.Directory.GetFiles(PercorsoOrdini & lblIdOrdinePassato.Text)
            ImgLstFiles.Images.Add(Icon.ExtractAssociatedIcon(fileName))
            LstViewDocumentiCaricati.Items.Add(IO.Path.GetFileName(fileName), ImgLstFiles.Images.Count - 1)
        Next

The error happen also if i share directory with sufficient permission...it create directory on network drive but go on error when try to list files.

The error are similar to this:

Value of \172.16.3.145\Directory\Docs\document.pdf is not a valid path for filePath

I'm not able to debug in production computer, so i think the error is in listing procedure code because all code firs work (create directory on network drive).

Someone could help me to understand why ?

Ron Maupin
  • 6,180
  • 4
  • 29
  • 36
  • 2
    You say you get errors, but you never say _what the errors are_. We'll need to know the exact error message(s) and where it is/they are thrown if we are going to be able to help. – Visual Vincent Feb 28 '17 at 16:42
  • Also, please do not write [**the language you are using in the title**](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles). – Visual Vincent Feb 28 '17 at 16:45
  • The error are similar to this: "Value of \\172.16.3.145\Directory\Docs\document.pdf is not a valid path for filePath" I'm not able to debug in production computer, so i think the error is in listing procedure code because all code before work (create directory and copy files on network drive) – Stefano Ravagni Feb 28 '17 at 17:26
  • Implement proper error handling and log the error along with its [**stack trace**](http://stackoverflow.com/questions/42143624/how-to-access-and-use-the-stack-trace-to-help-identify-a-bug). It is possible that `Path.GetFileName()` throws the exception, but I wouldn't understand why. -- Also, unrelated to your problem, but I'd recommend you to use [**`Path.Combine()`**](https://msdn.microsoft.com/en-us/library/system.io.path.combine(v=vs.110).aspx) when constructing paths. – Visual Vincent Feb 28 '17 at 20:01
  • Since you're using this on another computer, perhaps consider [**remote debugging**](https://msdn.microsoft.com/en-us/library/y7f5zaaa.aspx)? – Visual Vincent Feb 28 '17 at 20:05
  • I cannot do remote debugging because the network is protected from external access. I'll try to use path.combine() method but....teorically the code is correct, right ? I use also try catch construct but the error is this.... – Stefano Ravagni Mar 01 '17 at 15:17
  • I cannot install Visual studio at work location....and at home i have not a network for test and debug this error....in local drive all work great! – Stefano Ravagni Mar 01 '17 at 15:27
  • There's no problem with the code, no. That's why I need the stack trace so I can see which method causes the error. – Visual Vincent Mar 01 '17 at 17:09
  • Ok....in this time i substitute every code fragment for improve path.combine method....but....how can i take stack trace if i cannot debug in the production machine ? Return the ex.code from a try-catch construct could help or is not sufficient ? If i write a ex.stacktrace into a txt file could help ? – Stefano Ravagni Mar 01 '17 at 17:42
  • As explained in the post I linked to, you can access it via the [**`Exception.StackTrace` property**](https://msdn.microsoft.com/en-us/library/system.exception.stacktrace(v=vs.110).aspx), yes. But keep in mind: I might mot be able to help you solve this, but the Stack Trace can at least get us a hunch of what method causes the problem. – Visual Vincent Mar 01 '17 at 18:20
  • I used a new release wich capture the stack trace and i think have the solution (thanks to your help!). This is the stack trace: StackTrace: at System.Drawing.Icon.ExtractAssociatedIcon(String filePath, Int32 index) at System.Drawing.Icon.ExtractAssociatedIcon(String filePath) at MAGELIOS.FrmDocumentiOrdine.DialogCercaDocumento_FileOk(Object sender, CancelEventArgs e). So, the problem is the ExtractAssociatedIcon method when used in a network or shared folder... There is a solution for this or simply have i to verify when i'm in a shared directory and in this case skip this method? – Stefano Ravagni Mar 02 '17 at 14:00
  • I found this article from Stackoverflow:http://stackoverflow.com/questions/1842226/how-to-get-the-associated-icon-from-a-network-share-file . Could it be a valid solution to solve this issue ? – Stefano Ravagni Mar 02 '17 at 14:02
  • That seems like it could do the trick, yes. – Visual Vincent Mar 02 '17 at 14:45
  • Ok....i'll try and say you tomorrow...thanks for now! I have only one question about the trick code....whic mean last part of code after the [SuppressUnmanagedCodeSecurity] ?? Could make somes problem for other parts of my code ? – Stefano Ravagni Mar 02 '17 at 15:56
  • No. Attributes are applied to objects for a reason: They apply to that specific object only. – Visual Vincent Mar 02 '17 at 17:14
  • I confirm all work perfectly with the code supplied on the link above! I'm very happy and i want to send you my special thanks!!! – Stefano Ravagni Mar 03 '17 at 14:08

1 Answers1

1

With code provided in the link How to get the associated icon from a network share file all works perfectly. Tested today with no error or problem. Thanks to all!

Community
  • 1
  • 1