Hi Guys Im Trying To Use The Microsoft.WinAny.Helper Class i got from Here
i get an error when trying to delete a folder using the Quick Delete method
my code is
try
{
System.IO.FileInfo fi = new System.IO.FileInfo(textBox1.Text);
fi.Delete(OverwriteAlgorithm.Quick);
MessageBox.Show("File Sucsessfully Deleted", "Succsess", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
it give me an access is denied error at OverwriteAlgorithm.Quick
Additional information: Access to the path 'C:\Users\Test\Documents\Shredder\New folder' is denied.
please help me get access permissions if needed also im Using Windows Forms
Related
I am creating a C# UWP App, which creates files with broadFileSystemAccess capability.
Creating and writing to the file is no problem, but reading it fails with error message "Access to the path is denied even when I use storageFile.Path after writing it (so path is guaranteed to be correct and I can open the file in a text editor without problem).
Can anyone tell me, what I may can do to fix the problem?
Kind regards,
Wolfgang
Now I use following code to create a StorageFile, which can be read by my UWP app:
public static async Task<StorageFile> CreateStorageFileFromPath(string filepath)
{
string path = Path.GetDirectoryName(filepath);
string filename = Path.GetFileName(filepath);
var folder = await StorageFolder.GetFolderFromPathAsync(path);
return await folder.GetFileAsync(filename);
}
Kind regards,
Wolfgang
Hello I am having problems with testing if my embedded datbase exists.
I created a database like follows:
try {
SQLiteConnection.CreateFile("AttendanceDatabase.sqlite");
} catch (SQLiteException ex) {
}
And then I insert tables and data into the tables, everything works fine. When im saving data to the database im using the the connection string as follows:
conn = new SQLiteConnection("Data Source=AttendanceDatabase.sqlite;Version=3;");
Now my problem is everytime I run my program it creates the database over, and I would like to know how to test if the database exists it should not create the database over again.
I see the recomended way to do it is using the next statement:
if (File.Exists())
{
}
and I have tried using it as follows:
if (File.Exists("Data Source=AttendanceDatabase.sqlite;Version=3;")){
MessageBox.Show("File Exists");
}
but it does not want to go into the if brackets and display "File Exists".
So I would like to know what my path should be for my embedded database, that is if thats where my problem lies?
Thanx in advance!
I don't have a ton of context but if you update your check:
var basePath = "C:/<path to file>/";
if (File.Exists(basePath + "AttendanceDatabase.sqlite")){
MessageBox.Show("File Exists");
}
You might have more luck. If you give me more context to how you are running this I can help you with using services to lookup the file path. You can look it up based on assembles, approot, etc.
I'm trying to run a powershell script through batch job, I used the following code that works fine in a job :
System.Diagnostics.Process process;
System.Diagnostics.ProcessStartInfo startInfo;
;
process = new System.Diagnostics.Process();
startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.set_FileName("powershell.exe");
startInfo.set_Arguments("D:\\Documents\\OP3_FTP_Upload.ps1");
startInfo.set_UseShellExecute(false);
startInfo.set_RedirectStandardError(true);
process.set_StartInfo(startInfo);
process.Start();
when I use this code in a runbasebatch class, I have the following errors:
Failed to request the permission of type 'InteropPermission'.
Unable to create object 'CLRObject'
So I try to use the following to solve my permission problem:
Set permissionSet;
InteropPermission interopPermission;
;
interopPermission = new InteropPermission(InteropKind::ClrInterop);
permissionSet = new Set(Types::Class);
permissionSet.add(interopPermission);
CodeAccessPermission::assertMultiple(permissionSet);
...my first code example
CodeAccessPermission::revertAssert();
When I execute my batch job , I have no error message but nothing happens. The path is correct, the script also (parms corrects based on AOS)
I think the problem is my way to implement permissionSet and interopPermission classes, I know how to use it in case of CRUD operations on files, but how to use it in case of script execution? Can anyone explain me how (if possible)to manage those classes in my case of use?
Any other ideas to solve my problem are welcome.
This should be enough (in the method doing the CLR calls):
new InteropPermission(InteropKind::ClrInterop).assert();
Otherwise try to debug.
I am trying to create a Sqlite database using Monotouch 3.0.3.4. Everything works fine on the iPhone simulator, but I get the following error on the test iPhone:
DataLayer.CreateDatabase Exception: System.UnauthorizedAccessException: Access to the path "/private/var/mobile/Applications/4B4944BB-EC37-4B0C-980C-1A9B60DACB44/TestApp.app/myDatabase.db3" is denied.
Here is the code I am using:
// creates database and tables if they do not exist.
public void CreateDatabase ()
{
string sql = string.Empty;
string dbFileName = "myDatabase.db3";
try {
if (!File.Exists (dbFileName)) {
// create database
SqliteConnection.CreateFile (dbFileName); //This is where the error occurs
Console.WriteLine ("CreateDatabase: Database created.");
...
}
catch (Exception ex) {
Console.WriteLine ("CreateDatabase Exception: " + ex.ToString ());
}
...
I have also tried specifing the personal folder, but that has no effect. What do I need to do to make sure permissions are correct?
Thanks!
Monotouch 3.0.3.4
That's likely MonoDevelop 3.0.3.4. See About MonoDevelop to get the MonoTouch version.
"/private/var/mobile/Applications/4B4944BB-EC37-4B0C-980C-1A9B60DACB44/TestApp.app/myDatabase.db3"
On devices the applications are signed, so their content can't change (without breaking the signature). As such you're not allowed to change things in the .app directory.
You should create (or copy) the database in the Documents directory and then open the database as read-write.
See the linked article for more details.
I need to write string to an xml file in Silverlight. When I used the following code, the above mentioned exception "Attempt to access the method failed: System.IO.StreamWriter..ctor(System.String, Boolean)" has occurred.
using (StreamWriter sw = new StreamWriter("C:\Test.xml", false))
{
sw.Write(root.ToString());
}
Can anyone help me out in doing writing to xml file in Silverlight?
Silverlight is in a sandboxed mode where it has restricted access. You can write to "Isolated Storage", but you cannot create files on their hard drive.
http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragefile(VS.95).aspx
http://forums.silverlight.net/forums/p/22011/77243.aspx