So, my problem is, i want my program to delete all files inside the user's temp folder.
To go there and see if it works, i press WIN + R and type "%temp%" and hit enter...
It shows C:\Users\EDUARD~1\AppData\Local\Temp
But if i go into the users folder, my friend's user folder is named "EduardoPC".
If i press WIN + R and type "%userprofile%", it shows this path: C:\Users\EduardoPC
Im using:
Dim User As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
Dim PersonalTemp As String = User & "\AppData\Local\Temp\"
And also tried to use:
Dim User As String = SystemInformation.UserName
Dim PersonalTemp As String = "C:\Users\" & User & "\AppData\Local\Temp\"
Both return "EDUARD~1"
My friend's account is local, and when he boots up his pc, it shows "EduardoPC" in the login screen.
dim temp = Environment.GetEnvironmentVariable("TEMP", EnvironmentVariableTarget.User) -- The directory name with ~1 is just the DOS name (8 characters max) –
Jimi
Worked, thank you!
Related
Example i have picture folder located at
Dim path As String = "D:\Student Picture\Student-" + textbox_Search.Text + ".jpg"
Something like that. now i want the the picture folder to just paste it in debug folder can i call it without the drive letter something like this ??
Dim path As String = "\bin\debug\Student Picture\Student-" + textbox_Search.Text + ".jpg"
Its not working. The reason why i want to achieve this is example i use my program in another computer but the other computer don't have drive D: then my program will not work because in my code all of the student picture declared in drive D: thank you so much.
You can get the application startup path and create the folder in either the Debug or Release locations, depending which you're running. The folder would be created within the directory in which the end-user runs the compiled application.
Dim PicPath As String = Application.StartupPath & "\Student Picture
If Not My.Computer.FileSystem.DirectoryExists(PicPath) Then
My.Computer.FileSystem.CreateDirectory(PicPath)
End If
PicPath &= "\Student-" & textbox_Search.Text & ".jpg""
Small edit- I realised you wanted to include file name as well. Please do not use "+" when concatenating strings, the proper operator is "&" use the "+" operator only when youre doing math and some other unique cases, such as datatable expression column concatenation.
It is my first time building a database and I wanted to share a solution to a problem I encountered.
My problem was that I wanted to show different images for each record in a report, but I also wanted to be able to move the database. This was a problem. I search in all the forums and all the different solutions didn’t work. I also found an article written by Microsoft saying that the only way is to either store the full path to the images or to store the image in the database. But this causes a problem if the database is moved, or storing the images in the database will take up a lot of storage space.
The problem is that the codes doesn’t work for each record in the report, the codes are for the entire report. So writing codes to find the backend and the image folder would result in displaying the first image in the report for all the records in that report.
However I discovered, when only storing the name of the image in a table, it would sometimes work (but it shouldn’t have, because I didn’t have the path) but when I restarted the database it would stop working. Investigating further I discovered that whenever you open the file browser it will store the path in some kind of memory. As long as the path to the images is stored in the memory it will be able to link the images to the path.
So my solution…
When the form, from where you access the reports is opened, the file browser is opened and the path to the images is pasted in (using codes to find backend and the image folder) and then the browser is closed. And this creates a link to the image names (stored in a table) with the path. And each different images will be shows for each different records in the report.
Not a pretty solution. Whenever the form is opened, you will see a flash of the file browser. But it gets the job done.
In the load form event:
`' this will find the backend and the image folder:
Dim filepath As String
Dim strBackEndPath As String
Dim lenPath As Integer
Dim i As Integer
Dim j As Integer
strBackEndPath = CurrentDb.TableDefs("yourTabeInBackend").Connect
j = InStrRev(strBackEndPath, "=") + 1
strBackEndPath = Mid(strBackEndPath, j)
BackPath = Left(strBackEndPath, InStrRev(strBackEndPath, "\"))
filepath = BackPath & "YourImageFolder\"
'this will open the folder browser and paste in the path and close it:
Dim f As Object
Set f = Application.FileDialog(msoFileDialogFolderPicker)
Dim varFile As Variant
Dim strPath As String
Dim fileName As String
With f
.InitialFileName = (filepath)
.AllowMultiSelect = False
SendKeys "{ESC}", True
f.Show
For Each varFile In .SelectedItems
Next varFile
End With
`
You can move the pictures to a subfolder of the folder of your database.
Then save the pictures' names like this:
Picture1.jpg
Picture2.jpg
etc.
When you run the application, obtain the path to the pictures:
PictureFolder = CurrentProject.Path & "\FolderName\"
Then the path to a picture will be:
PictureFolder & Me!PictureFileName.Value
When you "move" your database, move both the database file and the folder with the picture files with it.
yup, i just encountered same problem and i agree with what Richard_Ha said, but in my case i solve it with storing image path on textbox and its work..
first textbox name "fileimage_txt" and bound to list of image filename on table
second textbox name "image_path" with property
Source Control : =GetImagePath()
visible : No (if u dont want it get printed)
and image control with property
Source Control : =[path_txt] & [fileimage_txt]
I am using Process.Start() and other options to open a folder location through Windows Explorer. It works fine on my local machine, but not through the server. All I need to do is open a folder location on a shared drive that every user has access to, I feel this should not be that hard. The same shared drive and parent folder is used to hold the application pages for the website as well as any templates and images that are used in the code.
I am using Telerik's RadAsyncUpload control to upload a file to the specific folder and then an image button to view all of the attached items within the folder based on a specific ID #. Here is the code for the button click event where it displays everything I have tried without success:
'DECLARE VARIABLES
Dim cadNum As String = hfCadNum.Value.ToString()
Dim path As String = My.Settings.CadLogFolder + "\" + cadNum.ToString()
If Directory.Exists(path) Then
'Process.Start(path)
'Process.Start("explorer.exe", path)
'System.Diagnostics.Process.Start(Environment.GetEnvironmentVariable("WINDIR")
'+ "\explorer.exe", path)
Dim pi As ProcessStartInfo = New ProcessStartInfo(path)
pi.UseShellExecute = True
pi.WindowStyle = ProcessWindowStyle.Normal
pi.Verb = "OPEN"
Dim proc As New Process()
proc.StartInfo = pi
proc.Start()
Else
lblErrFolder.Text = "There are no attached files."
End If
I don't get any error message when running this on the server, except for the first and last attempts, and no explorer window pops up. These are all of the suggestions that I have come across and none of them are working.
I don't believe this is a permission issue because the webpage is located in the same parent folder and all users have access to this shared drive.
I want to code a program in which a folder wouldn't be accessible to any of the users. I set it's attribute-number to 7 hence it became hidden, system file and read-only. But the folder can be accessed by any users.
I want a code in which a Message-box appears saying that the access is denied while its opened. Hope anyone can help me.
Thanks in advance
You can do it with ICACLS, run it in your code by using System.Diagnostics.Process.Start
' Your path here
Dim path As String = "X:\Path\Follows\Here.x"
Dim cmd As String = "icacls " & path & " /deny *S-1-1-0:(OI)(CI)(W,D,X)"
' You can also just use Process.Start even without "Imports System.Diagnostics"
System.Diagnostics.Process.Start(cmd)
I have a small program that creates a load of files and saves to a folder specified by the user. Currently the top of the userform looks like the following when initialised:
I'd prefer if when the userform opens and also when the dialog for choosing a appears (via the Destination button) that a general default is already shown:
Can the program find the pathway to a user's desktop?
To get the path to the users desktop, use:
PathToDesktop = Environ("USERPROFILE") & "\Desktop"
If you are doing this in excel-vba, the following code would save the current workbook as a copy to the user's desktop... you can probably figure out what you're doing from there.
Dim DesktopPath As String
DesktopPath = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparator
ActiveWorkbook.SaveAs DesktopPath & "filename.xls"