Hi community!
I have an application in VB.Net, in the user's computer is located in program files.
The users run always the program as an Administrators.
But in some cases; when the program try to rename a file in the program files the program throws the following exception:
The given path's format is not supported.
SOURCE = System.Security.Util.StringExpressionSet.CanonicalizePath
Also, happens when I try to copy a file.
The application does the rename or copy automatically and it's the same name for all the users
Example:
Rename(vOld, vNew)
FileCopy(vOld, vNew)
This exception only happen in Win7.
Somebody have an idea what is the reason to some users appear this exception?
This will happen when the user provides an invalid file name, for example one that includes colons.
You should validate that the user-entered file name does not contain any of the values in System.IO.Path.GetInvalidPathChars.
All it's my fault!
-_-'
I'm trying to rename this path:
C:\_MyFile.xlsx
To:
C:\MyFile.xlsx
In my computer all works fine because I have the both files (The users only has the file with the underscore).
When the program try to validate it try to rename the file "_C:\MyFile.xlsx" to "C:\MyFile.xlsx"
The exception don't give much information about my error...
Related
I have a client who has asked me to fix a problem with a corrupt user.config file. The config file has enough of an XLM header for the program to load the settings, but the rest of the config file is nulls (0x00) so the config loads, but then an error occurs when attempting to access any of its member. Note: the 0x00 value pops up in the error message later.
After much research, the common suggested solution seems to be delete the user.config file and then do a My.Settings.Reset but this doesn't work for me. The only solution that seems to work is to delete the user.config file, and then shut down and restart the program. The program starts and runs fine after deleting the user.config file. It creates a new user.config with default values and goes on its merry way with no problems.
What I have tried:
First:
Dim innerExcept As ConfigurationErrorsException = CType(cex.InnerException, ConfigurationErrorsException)
My.Computer.FileSystem.DeleteFile(innerExcept.Filename)
Then various combinations of the following:
My.Settings.Reset()
My.Settings.Reload()
My.Settings.Upgrade()
No matter what I try, I get the following error. Any thoughts?
System.Configuration.ConfigurationErrorsException HResult=0x80131902
Message=Configuration system failed to initialize
[truncated for brevity]
Inner Exception 1: ConfigurationErrorsException: '.', hexadecimal
value 0x00, is an invalid character.
I am new to postgres, probably missing something silly like (the correct name of my directory). Can someone guide me?
I am following book instructions, Practical SQL by Anthony DeBarros
Code:
copy us_counties_2010 from 'C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv' with (FORMAT CSV, HEADER);
Error:
ERROR: could not open file
"C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv" for reading:
Permission denied HINT: COPY FROM instructs the PostgreSQL server
process to read a file. You may want a client-side facility such as
psql's \copy. SQL state: 42501
copy us_counties_2010 from
'C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv' with (FORMAT
CSV, HEADER);
Expected:
Query returned successfully: 3143 rows affected
Actual:
ERROR: could not open file
"C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv" for reading:
Permission denied HINT: COPY FROM instructs the PostgreSQL server
process to read a file. You may want a client-side facility such as
psql's \copy. SQL state: 42501
All that is to be done is:
Go to Properties of that particular file by right clicking on it. Then, go to Security tab of the displayed Properties dialog box. Click on Edit option. Permissions dialog box appears, then click on Add button. Type 'Everyone' (without apostrophes) in the "Enter the object names to select" description box and click on OK button. Then, make sure all the checkboxes of "Permissions for Everyone" are selected by just ticking the "Full Control" check box to allow the control access without any restriction. Then, Apply and OK all the tabs to apply all the changes done.
You can now run/execute the query without any errors.
As the message tells you, Postres is not allowed to read the file.
If you want to fix that open the Task Manager, and click on "Show processes from all users". Look for the rows with the image name postgres.exe (likely more than one). Remember the value in the column "User Name" (it's probably NETWORK SERVICE). Open the properties of your file, add that user in the "Security" tab and grant read access to them.
Or use psql's \copy as the message suggests.
copy us_counties_2010 (your column name)//(country_code, latitude, longitude, country, population)
FROM 'D:\us_counties_2010 .csv' DELIMITER ',' csv HEADER
Your csv file should be in other than C drive. It can't access your C drive. Store it in D drive or any other it will work perfect.
Change the Location of data file and path to Drive['D:\us_counties_2010.csv' ] it will work.
The permission is denied because your files[us_counties_2010.csv] is in 'C' Drive ['C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv'] which is a Windows Drive and permissions are restricted and may not be changed easily & impossible without administrative privileges.
Good Luck & happy programming!
If you are using PSQL, run it as administrator, then you shouldn't have any problem when you are using COPY
In the case when creating a table as well as importing data from a CSV file, we can skip the query and use the program itself. To do this, simply right-click on your table in the tree on the left and select the Import/Export… menu item.
A window will appear with the slider set to Import. Then select the source file and set the format to CSV. Set the Header to Yes if your file has a header. The only thing left is to select the delimiter (usually a comma).
When you click OK, the data will be imported.
For a better understanding, you can refer original article.
https://learnsql.com/blog/how-to-import-csv-to-postgresql/
copy us_counties_2010 from 'C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv' with (FORMAT CSV, HEADER,DELIMITER ',');
Use this code instead of that
i try to rename a file using vb.net in this way:
my.computer.filesyste.rename(oldname,newname)
But if i use a software to recover files deleted, i find a file named :"_ldname", and if i recovery the file "_ldname" i have, in this way, two files equals.
Can i do this without have a duplicate of my file?
Best regards
Sebastiano
You cannot, this is a windows filesystem limitation and nothing to do with programming. Two files cannot have the same name in the same location.
The recovery software should be forcing a rename to Myfile(1).txt or something like that to distinguish between the two files.
You could always use:
If File.Exists(path) = False Then
To make sure the file doesn't already exists. Then if it does exist you could add a "(1)" to the file name.
By default AutoCAD installs a text based file called acad2010.lsp at the set location below
Dim FILE_NAME As String = "C:\Program Files\AutoCAD 2010\Support\acad2010.lsp"
However it my be that the user/ administrator/ or third party has changed the location of this file. Is it possible to then locate it using the following
Dim FILE_NAME As String = "C:\*\acad2010.lsp"
In other words search the entire c:\ drive for file acad2010.lsp?
If this doesn't work can you please let me know what would?
You could search for it with an FSO. It's not going to be fast however you do it but this is the fastest way I can think of.
http://www.microbion.co.uk/developers/fso.htm should give you a rough idea of how it's done.
Your solution will not work. Is not possible to locate it using *. (BTW is possible in ms-builds scripts). The only way of doing it is:
1- Create a FindFile function (check for example
http://xlvba.3.forumer.com/index.php?showtopic=125)
2- Use it to locate the exact path of the file. (It could be really time
consuming)
3- From this point your code is the same...
Unfortunately, you can't use wildcards in a filepath. You have two options:
Prompt the user for the file location using the "Open File" dialog. The code to do this varies based on which Office product you are using. In Excel, you would use the Application.FindFile method (more info here).
Write your own function to search the filesystem for the file. Microsoft provides an example here.
If that file is used by internal functions of the application, the installer will have recorded a registry key for the file's location.
Open regedit.exe and search for the file name and path.
You can read a registry entry using this VBA one-liner:
CreateObject("WScript.Shell").RegRead(strRegPath)
You may need a terminating backslash on the key address, but that's a safe and simple registry access method. More details on the MSDN site:
https://msdn.microsoft.com/en-us/library/x05fawxd%28v=vs.84%29.aspx
Does anyone have an idea how you can catch the exception that cobol throws if you try to open an IO file if it doesn't exist, and then create a new file?
The OPTIONAL phrase on the SELECT cause will do this:
SELECT OPTIONAL FILE-A
ASSIGN TO "INFILE"
ORGANIZATION INDEXED.
If OPEN IO the file will be created if necessary. For OPEN INPUT, the file not be created but treated as being at EOF and all random reads will be "INVALID KEY".
I'm pretty sure this is an ANSI standard clause, but can't remember when it showed up.
I don't know what version of Cobol you use or what platform you use it on. My program checks first to see if the file exists before it tries to open it. I use Unisys Cobol 85 on the MCP mainframe platform. The messages are lame, but who cares?
Here is a snippet from a job that runs daily:
968545 IF ATTRIBUTE RESIDENT OF OU3-WORK-LIST-FILE = VALUE TRUE
968550 DISPLAY "PROGRAM SHOWS ATTRIBUTE TRUE"
968555 OPEN EXTEND OU3-WORK-LIST-FILE
968560 ELSE
968565 DISPLAY "PROGRAM SHOWS FALSE"
968570 OPEN OUTPUT OU3-WORK-LIST-FILE
968575 END-IF.
968580
Cathy