2017-06-24 47 views
-1

我使用這段代碼保存在我的應用程序文件如何獲取此代碼創建的文件路徑?

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

所以現在我有一個TextBox1中,我想,以顯示它如何 最後保存圖片的路徑?

問候,,,,

+0

做了推測,'TextBox1.Text = IO.Path。 Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop),filePath)' – Blackwood

回答

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 
+0

偉大的Mike_OBrien先生的工作,但如果我想如果第一個cr eate桌面上的文件夾,然後將圖像保存在該文件夾中? – user206402

+0

@ user206402:你真的應該自己做一些研究:https://www.google.com/search?q=VB.NET+create+folder –

0

感謝所有我已經成功地`

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 
相關問題