Write to file in uwp that has been drag-dropped from explorer - file-io

If file is dragged and dropped from file explorer it has FileAttributes.ReadOnly flag for StorageFile.Attributes parameter. In that case using StorageFile api to write to file will give error. How to write to file in this case??

In this case PathIO api can be used to write to file (unless file is a system file). Convert data to write into bytes array and then add following code to write to file:
await PathIO.WriteBytesAsync(file.Path, bytes);
This will write to these files without any error. You don't need any additional permission like broadFileSystemAccess for this.

Related

After building an App(Android) using Kivy, Reading and writing text file(authorization completed)

I am using Filechooser, and checked whether the correct file is loaded using the print function until the data path.
text file name: A.txt
self.data_name = str(self.list_data_load.selection[0])
self.fdata=self.data_name
check_error= 'Path' + self.fdata
f=open(self.fdata,"r")
/emulated/0/data/A.txt
#F=f.readline()
but, when I try to use readlines, the app crashes and shuts down in Andorid.
I'm not sure if I need to grant additional permissions to read text files in external storage.
I need some help please.

load file with csv extension in ssis

I have to load file with csv extension from one particular folder to data base in ssis. file name is not known but folder and extension is fixed.
To load the content of a file, the file name with folder path is required else the connection manager can not be validated and configured.
The easiest way is to get file name is using a For Each Loop container:
Select the option [Foreach File Enumerator]
Provide the Folder path and extension (like *.csv) you already have.
Get the File Name in a variable and use it within the Source of the data flow task within the For each Loop container.
Refer

Visual Basic read text file and delete files from that file

I know how to tell my program how to read a file but I dont know how to use that information to delete some files from that text file.
Example;
I have a text file called ban.txt inside that file there are two lines with text abc.exe and cba.exe
I want my program to read content of ban.txt and the delete those specified files.
Assuming that you know how to read the file and find the file names, then just add this statement to a for-each:
My.Computer.FileSystem.DeleteFile(strFilename)
There are also options for displaying error messages and sending the file to the recycle bin.
My.Computer.FileSystem.DeleteFile("C:\Test.txt", FileIO.UIOption.AllDialogs, FileIO.RecycleOption.SendToRecycleBin)

load script from other file extension?

is it possible to load module from file with extension other than .lua?
require("grid.txt") results in:
module 'grid.txt' not found:
no field package.preload['grid.txt']
no file './grid/txt.lua'
no file '/usr/local/share/lua/5.1/grid/txt.lua'
no file '/usr/local/share/lua/5.1/grid/txt/init.lua'
no file '/usr/local/lib/lua/5.1/grid/txt.lua'
no file '/usr/local/lib/lua/5.1/grid/txt/init.lua'
no file './grid/txt.so'
no file '/usr/local/lib/lua/5.1/grid/txt.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './grid.so'
no file '/usr/local/lib/lua/5.1/grid.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
I suspect that it's somehow possible to load the script into package.preaload['grid.txt'] (whatever that is) before calling require?
It depends on what you mean by load.
If you want to execute the code in a file named grid.txt in the current directory, then just do dofile"grid.txt". If grid.txt is in a different directory, give a path to it.
If you want to use the path search that require performs, then add a template for .txt in package.path, with the correct path and then do require"grid". Note the absence of suffix: require loads modules identified by names, not by paths.
If you want require("grid.txt") to work should someone try that then yes, you'll need to manually loadfile and run the script and put whatever it returns (or whatever require is documented to return when the module doesn't return anything) into package.loaded["grid.txt"].
Alternatively, you could write your own loader just for entries like this which you set into package.preload["grid.txt"] which finds and loads/runs the file or, more generically, you could write yourself a loader function, insert it into package.loaders, and then let it do its job whenever it sees a "*.txt" module come its way.

CFSCRIPT - How to check the length of a filename before uploading

I ran into this problem when uploading a file with a super long name - my database field was only set to 50 characters. Since then, I have increased my database field length, but I'd like to have a way to check the length of the filename before uploading. Below is my code. The validation returns '85' as the character length. And it returns the same count for every different file I upload (none of which have a file name length of 85).
<cfscript>
missing_info = "<p>There was a slight problem with your submission. The following are required or invalid:</p><ul>";
// Check the length of the file name for our database field
if ( len(Form["ResumeFile1"]) gt 100 )
{
missing_info = missing_info & "<li>'Resume File 1' is invalid. Character length must be less than 100. Current count is " & len(Form["ResumeFile1"]) & ".</li>";
validation_error = true;
ResumeFileInvalidMarker = true;
}
</cfscript>
Anyone see anything wrong with this?
Thanks!
http://www.cfquickdocs.com/cf9/#cffile.upload
After you upload the file, the variable "clientFileName" will give you the name of the uploaded file, without a file extension.
The only way to read the filename before you upload it would be to use JavaScript to read and parse the value (file path) in the file field.
A quick clarification in the wording of your question. By the time your code executes the file upload has already happened. The file resides in a temporary directory on the ColdFusion server and the form field related to the file upload contains the temporary filename for that file. Aside from checking to see if a file has been specified, do not do anything directly with that file or you'll be circumventing some built in security.
You want to use the cffile tag with the upload action (or equivalent udf) to move the temp file into a folder of your choosing. At that point you get access to a structure containing lots of information. Usually I "upload" into a temporary directory for the application, which should be outside of the webroot for security.
At this point you'll then want to do any validation against the file, such as filename length, file type, file size, etc and delete the file if it fails any checks. If it passes all checks then you move it into it's final destination which may be inside the webroot.
In your case you'll want to check the cffile structure element clientFile which is the original filename including extension (which you'll need to check, since an extension doesn't need to be present and can be any length).