I have a problem on my C# webapp
I need to copy a file from some network path
\\server01\sharedFolder\myfile.ext to inetpub/upload folder, and show the link to the user download the ext file.
When i use File.Copy (C#) the file lost all permissions and the browser user can't download the file. The iis keeps asking a windows credential to download the generated file.
I've tried to register .ext mime type and set file permission using FileSecurity.AddAccessRule without success.
how can i fix this ?
Related
I need to open a kmz file from the mobile app in order to see it in google earth, So i saved the kmz file in the StreamingAssets and i copy it to the persistentDataPath, Also the file is unable to open when i copy it to this folder.
Im calling it with this:
Application.OpenURL("file://"+Application.persistentDataPath + "/CR.kmz");
I already granted the file permissions.
I dont know how to open files from the storage with code. Help.
I have a file located inside a folder on my server: F:\Data\Attachments\a.pdf.
I'm using Blazor server app with asp.net 5.0 and C#. Up to now, the user that uses the application can upload this file. This file is correctly saved inside my server folder.
I can open the file with the powershell on my computer on which the Blazor Server App is running thanks to \\ip_server\Data\Attachments\a.pdf and I checked the permissions of the folder on the server.
I want to create a button that consent to download the file on the client machine (so, notify the browser and open the save dialog to choose the destination) or something similar because I tried everything without success.
I also tried to open the file using a link <a href="file:////ip_server/Data/Attachments/a.pdf" >link</a>.
When my file was located inside the project folder, I had no problem. So, how can I solve this issue? Is there something that I'm missing?
If you need any other information, please ask.
Thanks in advance.
I'm trying to copy excel file from server shared folder to local system folder using windows service C#.
But throw below error
The Microsoft Access database engine cannot open or write to the file It is already opened exclusively by another user, or you need permission to view and write its data.
Code:
string filename = #"\\Datawarehouse\Data\Result.xlsx";
string filePath = #"C:\Test\Result.xlsx";
System.IO.File.Move(filename , filePath);
The error you are showing can be caused by a few causes:
The file you are attempting to open a file which still is open on your machine (or if it is in the cloud then someone still has it open)
If the file is in the cloud, then it could be caused by security settings so you can try to move the file locally onto the server.
If the file is local then it could be caused by permissions issues, you can try and grant the user "Everyone" to test if this resolves the error.
I can't delete a pdf file from a shared drive (Windows mapped drive) from my c# Winform desktop program which runs on Windows 10 OS. The pdf file was created by Crystal Report in my c# program and when there is a revision, I need to delete the old pdf file and write the new one. I will get access denied error (HResult=0x80070005) when the program tries to delete the file. This only happens when the I try to delete it from a shared drive. If I generate the pdf file in the local drive (c:), and delete it from the local drive, then everything is find. I can manually delete the pdf file from File Explorer, but not from my c# program.
In addition, if the file is not a pdf file, then there is no problem to delete it from the shared drive.
It is weird that this only happens to pdf file or a file with .pdf extension. If I create a simple text file (test.txt) with C++ and save it in the shared drive, I can delete it without any problem. But when I create the same text file and name it as test.pdf, then I can't delete it.
HResult=0x80070005 seems only links to permission issue, but I strongly believe my case is NOT a permission issue because if the file is *.txt, then I can always delete it without any issues.
To rule out the possibility of the pdf file that may be still linked with the Crystal Report or opened by some programs, I copied the pdf file from the shared drive and save it in my local drive (c:) and wrote a simple c++ program to test if I can delete it, and it failed. Can't delete it. I can only delete it if the pdf file was created and saved in the local drive originally. And if the pdf file is copied from the shared drive to the local drive, then I can't delete it.
I would appreciate it if someone can shed some light on it.
I think (you/your app) don't Have Permission To Delete a File
Go to the folder that contains the PDF File.
Right-click on that folder and choose Properties.
Navigate to the Security tab.
Click on Edit, then click Add.
Under the Enter the object names to select box. Type
"Everyone"(without quotes) and click on Check names. Click OK.
A new window will open up with the Security tab. Under Permissions for
Everyone, check the Full control option. Select Apply and OK.
Ownership is already allowed for the folder.
Now you Can delete PDF files programmatically
Don't Have Permission To Delete a Folder
Thanks for trying to provide solutions for this problem. With a help from a friend, I finally found the root cause of the problem. It is the Norton antivirus that prevents me from deleting a certain types of files. .pdf is one of them. After I unchecked the .pdf from Norton, it works like a magic.
It is the antivirus program that prevents me from deleting .pdf file programmatically.
I am supporting an Android app written in Xamarin which has a feature where the user can email logs and SQLite db file to a support email address. It does this by zipping up the files and then copying the ZIP to the public Downloads folder, then attaching them to an email.
It uses the Download folder so that other apps have permission to access the files, and I can see them if I connect to my PC with a USB cable.
This has worked fine until now - to deploy an update to the Play Store I now have to target API 29 and this no longer works. The function to move the ZIP file to the Download folder fails.
I use the following method to get the path to the new file in the download folder:
var path = Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).AbsolutePath, filepath);
although VS is showing this method as obsolete:"deprecated"
When I try and move the ZIP file to it, I get
System.UnauthorizedAccessException: Access to the path "/storage/emulated/0/Download/logs.zip" is denied.
I have added
android:requestLegacyExternalStorage="true"
to my manifest, which has made no difference at all.
If I switch back to targeting API 28, all works fine.
Is there anywhere at all I could put the file to allow the user's default email app to read it as an attachment?
If you have requested for the read and write runtime permissions. Check the suggestions is the link below. Android 9.+ API 29: /storage/emulated/0/Pictures/myPic.png open failed: EACCES (Permission Denied)
And use the code below to replace the deprecated method.
var path = Path.Combine(GetExternalFilesDir(Android.OS.Environment.DirectoryDownloads).AbsolutePath, filepath);