Environment GetFolderPath issue

Moordoom

Member
Joined
Nov 12, 2013
Messages
23
Programming Experience
1-3
I am having an issue with Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

Declarations from Earlier in the sub

VB.NET:
Dim oExcel As Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Add(Type.Missing)
oSheet = oBook.Worksheets(1)

Issue area...

VB.NET:
Dim fileName As String = "EmployeeID_"
Dim fileID As String = TextBox2.Text
Dim Path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim exten As String = ".xls"
Dim finalPath As String
finalPath = String.Concat(fileName, fileID, exten)

oSheet.Columns.AutoFit()
oBook.SaveAs(finalPath, XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing)

Rather than it selecting the C:\Users\UserName\Desktop as default path, It pulls up the path selection window, and no matter what location I chose, it saves to C:\Users\UserName\Documents in the correct File name (ie. EmployeeID_9999.xls).

Did I miss a reference or import?
 
It will probably do that if the path is not valid or has write limitations. Have you actually verified what finalPath is? Since you don't use Path.Combine method to combine the path there is a risk you are missing a directory separator char.
 
Duh, I left my Path variable out :)

Still have an issue though.

When it gets the final path, it then puts up a folder list, and allows me to select a different folder.
But the saves to the finalPath variable location of C:\Users\UserName\Desktop\EmployeeID_9999.xls
 
Last edited:
I just noticed you have a variable named "Path" and probably had no idea what I meant when I said "Path.Combine method". What I was referring to was the .Net Path class here: Path Class (System.IO) It has many useful methods for working with paths and filenames.
 
Back
Top