【问题标题】:How to access disk in network如何访问网络中的磁盘
【发布时间】:2017-02-28 16:39:56
【问题描述】:

我有例程将一些文档存储到一个目录中,该目录在本地驱动器上运行,但如果我使用路径作为“\\172.16.3.145\Directory”,则会出现网络驱动器错误。

我使用此代码创建所需的子目录:

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

此代码工作并在路径中创建目录也为“\\server\directory”,但当我尝试使用此其他代码列出列表视图中的所有文件时出现错误:

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

如果我以足够的权限共享目录也会发生错误...它在网络驱动器上创建目录但在尝试列出文件时继续出错。

错误类似这样:

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

我无法在生产计算机中调试,所以我认为错误在于列出程序代码,因为所有代码都可以工作(在网络驱动器上创建目录)。

有人可以帮我理解为什么吗?

【问题讨论】:

  • 你说你得到了错误,但你从来没有说错误是什么。如果我们能够提供帮助,我们将需要知道确切的错误消息以及它在哪里/它们被抛出。
  • 另外,请不要写the language you are using in the title
  • 错误类似于:“\\172.16.3.145\Directory\Docs\document.pdf 的值不是 filePath 的有效路径”我无法在生产计算机中调试,所以我认为错误在于列出程序代码,因为所有代码在工作之前(在网络驱动器上创建目录并复制文件)
  • 实施正确的错误处理并记录错误及其stack tracePath.GetFileName() 可能会抛出异常,但我不明白为什么。 -- 另外,与您的问题无关,但我建议您在构建路径时使用Path.Combine()
  • 既然你在另一台电脑上使用这个,不妨考虑remote debugging?

标签: vb.net networking disk


【解决方案1】:

使用链接How to get the associated icon from a network share file 中提供的代码,一切正常。今天测试没有错误或问题。谢谢大家!

【讨论】:

    猜你喜欢
    • 2021-09-23
    • 1970-01-01
    • 2011-08-17
    • 1970-01-01
    • 2019-03-11
    • 2021-08-09
    • 2019-05-24
    • 2010-10-20
    • 2011-05-23
    相关资源
    最近更新 更多