I have a website that creates a txt file and saves it with a timestamp to the webserver directory.
I need a client based app to list all files in the directory to download to the client server for processing but cannot find a way to have them listed in a listbox without specifying the full file name
i.e. TB2014-09-08_11h48m25_765.txt is a full name. TB stays constant and the files are always .txt)
you want the GetFiles method in the Directory class (System.IO namespace). Something along these lines:
Dim files As String() = Directory.GetFiles("c:\YourFolder", "TB*.txt")
For Each filename In files
Console.WriteLine(filename)
Next
Related
Very new to this so please help. Im trying to mass update files in a static folder location, many files in one folder.
What i want to do is run VBA macro in Excel 2010 to goto a network location folder, open the fist file in the folder. Unprotect the workbook and worksheets call another marco to run changes then protect the worksheet close the file and then move onto the next file in the folder until all files have been corrected.
I have created the marco to make the changes, this is called "Edit"
File types are xlsm and the workbook and worksheet are password protected
How can i automatically run the macro to goto the network location and in series open each file, unprotect, call the macro, then re protect the document close file and move onto the next file until they are all updated.
Have you tried running the MacroRecorder while performing the tasks you've listed. You can then pinpoint the exact lines of code you need to add in.
Assume I want to write to a new file created within the space of my webapp.
One way would be use getServletContext().getRealPath("/") and use that String to create a new file on the server. However, often I come across advice like not using getServletContext().getRealPath("/").
Can someone please let me know of another way to write a new file within my webapp?
Many thanks.
Have some configuration property containing the absolute path of a directory outside of the webapp and web server path, read this path from the configuration property, and write to this directory.
To serve files from this directory, write a servlet that takes the name or ID of this file as parameter, reads the file from the directory, and sends its content to the response.
This will
work even if the app is deployed as a war file and never unzipped to the file system
allow you to redeploy the next version of the app or server without deleting all the uploaded/created files
allow you to add whatever control you want on the uploaded/created files, instead of making them available to everyone
In short, treat these files as data, stored in a database which happens to be the file system instead of a SQL database.
Salvete! When we set up the asp.net file-uploading control called "NeatUpload", it saves its files to a temporary location, either "YOUR_APP_ROOT /app_data/NeatUpload_Temp/", if the directory is writable, or to the system's temp folder. However, the demo does not seem to actually upload any files, nor does it include an example for saving the files to a particular directory.
How do we save the file we have uploaded and move the uploaded file to a particular folder? My only clue from the documentation is that it has to do with UploadStorageProvider, but I need some help to implement this.
if you read the documentation 3.3 point 6 :
In your codebehind file, process the uploaded file. If you are using
the InputFile control, the uploaded file's client-specified name, MIME
type, and contents can be accessed via inputFileId.FileName,
inputFileId.ContentType, and inputFileId .FileContent, respectively.
If you want to keep the uploaded file, you must use the
inputFileId.MoveTo()method to move the uploaded file to a permanent
location. If you do not, NeatUpload will automatically remove the
uploaded file at the end of the requestto ensure that unwanted files
do not fill up the filesystem. The following code will put the
uploaded file in the application's root directory (assuming sufficient
permissions):
and so on. I hope this is what you are after.
I have a StringBuilder object which I have built with comma seperated values, which I would like to save as a .csv file.
I know how to stream the data as CSV, but how can I physically save the data as a .csv file, on the server?
Currently I stream the CSV like the following, where sb is StringBuilder:
Response.Clear()
Response.AddHeader("Content-Disposition", "attachment;filename=List.csv")
Response.ContentType = "text/csv"
Response.Write(sb.ToString)
Response.End()
I assume you already know how to create csv, so check this question that shows how to save stream to file. As you're using ASP.NET just make sure you have the appropriate permissions to modify.
Conclusion
As you want to make the download available to user(instead of save it in the server) and csv is basically a text file check out this
It's not different than writing a normal file. If you want to save the file to a folder in your application, you should use Server.MapPath("~\MyCsvFiles") to get the physical path of the file.
Depending on the version of IIS, ASPNET or NETWORK SERVICE needs write permissions on the server folder you are writing to; then just write the CSV file out with StreamWriter or your preferred method. If you really want an Excel file, then consider using EPPlus.
I am trying to create a zip file and save it using DotNetZip library in ASP.NET application.
But for some reason i get a
Access to the path is denied
error when i try to save it.
I changed the TempFileFolder to another folder and have given permissions to it. Still no luck.
Dim zipFile As New ZipFile()
zipFile.AddFile(filePath)
Dim tempFilePath As String = "Report.zip"
zipFile.TempFileFolder = "D:\Temp\"
zipFile.Save(tempFilePath);
I found a question but the answer did not help me.
From the above question, one answer mentioned:
Also, the tempFilePath in your example doesn't include a full path, could it be that it is trying to save the ZIP into a different folder from the one you are expecting (and have assigned permissions to)?
How to figure out to which folder it is trying to save even though I mentioned TempFileFolder as D:\temp\?
Any thoughts?
Since you said you 'gave permissions' I'm assuming that you provided the account(s) which run the ASP.NET and IIS processes file Read/Write permissions to the folder where you're trying to save this file.
The 'Temp File Folder' is just what its name describes: a temporary file folder. It's a holding place in case the library needs to do some file I/O. it's not a base file.
Modify the code to provide a fully qualified path name to save the file to:
Dim zipFile As New ZipFile()
zipFile.AddFile(filePath)
Dim tempFilePath As String = "D:\Temp\Report.zip"
zipFile.TempFileFolder = "D:\Temp\"
zipFile.Save(tempFilePath)
Check if the file is not Read Only