I am modifying old application and I have to add functionality to allow user view a file from SQL. File needs to be saved in temporary folder and deleted after closing application. I've managed to do all above, but I have to get filename of downloaded file (now Im using a string variable filename = "TemporaryDoc").
How can I get a filename from a data that is stored in datagridview.Rows(0).Items(0) ?
Related
I am trying to create a text file that stores a folder path. This text file is then referenced via a vba sub. The path I want to use is something like:
"C:\Users\" & Environ("username") & "\AppData\Roaming\Microsoft\Templates"
This works fine in the sub but I've tried all kinds of variations in the text file but none of them get recognised and trigger error 52 - bad file.
Is there a way to make this work? I'm trying to allow people to set a different file path without needing to modify the code.
If you are trying to provide a path to the folder where user templates are stored then you could try
ActiveDocument.AttachedTemplate.Path
as an alternative (returns the path to the folder where the current template is stored for the user).
Otherwise store the path template as something like
"C:\Users\###UserName###\AppData\Roaming\Microsoft\Templates"
Which gives you a single string to retrieve. Then you can use the VBA Replace function to change the ###UserName### to the value of Environ("UserName)"
my_user_path = replace(my_path_template, Environ$("UserName"))
You might also want to explore using either a CustomDocumentProperty, or a Variables, to store your path template as this keeps the path template string as part of the Document or Template and not in a separate file.
I'm working with vb.net 2008 as well. But I have a question.How to remove a file path like this C:\users\myDocu\debug\Dbase.accdb and I only want is the file name Dbase.accdb. Because I want to transfer my files in another computer but the problem is the file path. I always need to change the entire location in my codes to run without debug.
To get the filename without the path, you can use Path.GetFileName.
But if you want a painless way to find a place to store your database, consider putting it into the application data folder (AppData). You can get this folder with Environment.GetFolderPath and Environment.SpecialFolder.ApplicationData, using it like this:
Dim pathToDb = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"Dbase.accdb")
if you want to use the file locally. If you want to share the file between different instances of your application in a network, put the path e.g. in a config file like App.Config.
Try this:
Dim FullFilePath As String
Dim FileName As String
FullFilePath = "C:\users\myDocu\debug\Dbase.accdb"
FileName = Mid(FullFilePath,InStrRev(FullFilePath,"\") + 1)
I'm trying to use MS Access to make a simple database of the store I work in and I have to insert photo's and I'm doing so by having a column where the filepath is stored eg. "C:\User\WL\Documents\Databasefolder\Pictures\img_xxxx.jpg" but when I hand over the file to my boss, the filename will be wrong as he will put it in a different folder.
So I'm looking for somekind of function that changes the "C:\User\WL\Documents\Databasefolder" to the current directory of the database with included pictures. I have almost no experience with SQL or Access alltogether, hence I came here.
You can retrieve the path for the user's Documents folder like this:
DocFolder = Environ("HOMEDRIVE") & Environ("HOMEPATH") & "\Documents"
What is the best was I can open a txt file in a SSIS and store the first line as a variable.
I want to put a list of accounts in the txt file and use them in a SQL task.
Refer to the link #Ozren gave you, to create a proper flat file connection e.g myfile and variable e.g.HeaderLine. Then create a script task, put HeaderLine var in read/write variables and code it with:
System.IO.StreamReader file =
new System.IO.StreamReader(Dts.Connections["myfile"].ConnectionString);
Dts.Variables["HeaderLine"].Value = file.ReadLine();
file.Close();
That's pretty much it, then you can put a standard DataFlow to read filedata from file to DB or resultset.
You'll have the first line in HeaderLine variable, which you can use anywhere you want in the SSIS package.
I am trying to update some local access databases from a web database. When I am accessing the web page, I want the user to select a folder on the local hard drive where the DB's reside that will be updated by the program. I actually have been using the File Upload control to do this as it has allowed me to check the file extensions on the local DB's their file size and other misc. items.
This captures the full path with the file name...
fileName = FileUploadAccess.PostedFile.FileName.ToLower
Now I have a need to capture the full path of the db's on the local hard drive. I can get the full path with the filename, but then I need to write a bunch of code to strip the filename from the path variable.
Is there a simple way to capture the path of the location the DB when the file location is selected, something like this....
Dim thePath As String = System.IO.Path.GetFullPath
Thanks for any suggestions.
You can use IO.Path.GetDirectoryName
Here is a sample code:
Dim MyDirectoryPath As String = System.IO.Path.GetDirectoryName(MyFullPath)