【问题标题】:How to get file's path created by this code?如何获取此代码创建的文件路径?
【发布时间】:2017-06-24 01:39:01
【问题描述】:

我正在使用此代码在我的应用中保存文件

 Dim filePath = String.Format("image{0:yyyyMMddHHmmss}.png", DateTime.Now)
    PictureBox1.Image.Save(IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), (filePath)))

所以现在我有一个 textbox1 并且我想在其中显示最后保存的图像的路径 怎么样?

问候,,,,

【问题讨论】:

  • 大概是TextBox1.Text = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), filePath)

标签: vb.net file path save


【解决方案1】:

我以前做的是一步生成路径,然后使用生成的变量进行保存和显示。

所以而不是:

Dim filePath = String.Format("image{0:yyyyMMddHHmmss}.png", DateTime.Now)
PictureBox1.Image.Save(IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), (filePath)))

试试:

'Generate the Path
Dim path As String = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), String.Format("image{0:yyyyMMddHHmmss}.png", DateTime.Now))
'Save using the generated path
PictureBox1.Image.Save(path)
'Display the path
textbox1.Text = path

【讨论】:

  • 伟大的 Mike_OBrien 先生工作,但是如果我想先在桌面上创建文件夹然后将图像保存在该文件夹中呢?
  • @user206402 :你真的应该自己做一些研究:google.com/search?q=VB.NET+create+folder
【解决方案2】:

谢谢我已经成功了`

  Dim filename As String = String.Format("image{0:yyyyMMddHHmmss}.png", DateTime.Now)
    Dim filePath1 = (IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), (filename)))
    Dim filePath2 = (IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), ("RMSS")))
    If IO.Directory.Exists(IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), (" RMSS"))) = True Then
        TextBox1.Text = filePath1
        TextBox2.Text = filePath2 & "\" & filename
        PictureBox1.Image.Save(filePath1)
        My.Computer.FileSystem.MoveFile(TextBox1.Text, TextBox2.Text, True)
    Else
        TextBox1.Text = filePath1
        TextBox2.Text = filePath2 & "\" & filename
        PictureBox1.Image.Save(filePath1)
        My.Computer.FileSystem.MoveFile(TextBox1.Text, TextBox2.Text, True)
    End If

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-30
    • 2019-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    相关资源
    最近更新 更多