I have excel file and it gives error "Could not decrypt file.". When I open excel file it is opening and not prompt me for any password.
But when I check its protection from toolbar in excel. It shows file is protected.
How can I read that file using OLEDBConnection.
I had a user with this issue today... I just told her to either unprotect the worksheet
In my specific case, she actually wasn't able to unprotect the worksheet since it required a password to unprotect it, so I just had her copy/paste the data into a new Excel file instead.
Related
I have encrypted a file with c# and gave it the extention .crypted. The file extention .crypted is associated with my program. So if i double click the file i get a password request dialog from my program. After entering the correct password my program decrypts the file and writes it unencrypted to the disk without the .crypted extention, so that i can run it. After using the file i just delete the unencrypted file and if the file was altered i use my program to reencrypt the file first. But u can easily use a file recovery program to get unauthorized access to the unencrypted file. Thats why i dont want to write unencrypted files to the disk after my program decrypts them. Is it possible to open an encrypted file without ever writing it to the disk? Like saving the unencrypted file to the ram/memory and opening it from there? I dont want to write a whole file system for that. The encrypted files should stay on NTFS or ext4. I think i need to change the code at this point:
using(CryptoStream cryptoStream = new CryptoStream(fileStream, rijndael.CreateDecryptor(), CryptoStreamMode.Read))
{
// write unencrypted file to memory and execute or something else?
}
I need to open a secured password protected PDF files programatically in ASP.NET using C#
I don't want to enter the password manually when it opens.
When the file is downloaded to the local drive it must ask the password to download or print the file.
I am using PDFsharp
You can specify the password in the call to PdfReader.Open to open the document. You can then create an unprotected copy of the PDF, e.g. to print it without password prompt.
See also:
http://www.pdfsharp.net/wiki/UnprotectDocument-sample.ashx
I use open XML to export excel file. SpreadsheetDocument.Create requires a file destination.
I want to get this file destination from user similar to a SaveFileDialog in Winforms.
How I get file destination from user? I use Asp.Net 4.0 and OpenXML SDK 2.5 .
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(destination, SpreadsheetDocumentType.Workbook);
For this functionality even if you use open/save dialog, it would show the client locations not the server locations. So here question is, do you want to save that file to the client machine or at the server machine?
If you want to save it to client machine then first save it on the server by any name and location you want and then initiate a download after that. It will automatically prompt download dialog in the client browser and there user would be able to select the location and filename (depending on the client browser settings).
If you want to save it only on server then just before generating the spreadsheet, prompt user for entering the filename (on the page from where the request is generated). If some of your folders are accessible to user then you can also prompt user to select one of the folders, otherwise choose one as per your choice/requirement. Use the filename and the location to generate the spreadsheet.
when a webserver is streaming a file down to the client, you don't have control of the destination folder. All you can do is:
specify the contents type (to aid client in determining how to handle)
specify filename
(I think) tell the client browser to save the file vs. displaying it automatically in the registered application (for example, PDFs usually display in the browser, but setting up the streaming correctly could force Save File dialog instead)
If you need to "cache" the file ion the web server, you export to a server folder that your server process has write permissions to. Then you stream to the client - the client will get the prompt from their browser and save where they want.
Look at Server.MapPath for example - it'll map virtual path to physical on your server. the question of permissions remains.
Depending on your particular case, you may be able to avoid saving to the server, if the export library has a way of returning a byte array or a stream, instead of saving to a file. In that case you just stream the return result to requester.
I am not familiar with the SDK you're using, but quick googling reveals this method of returning the document in a stream:
using (MemoryStream stream = new MemoryStream())
{
using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook, true))
{
... work with the spreadsheetDocument, if needed
... prepare and stream to browser
}
}
Here's one of the references to your SDK I found
Use Environment.SpecialFolder enumerations. If you are looking for my documents then:
var destination = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Create(destination, SpreadsheetDocumentType.Workbook);
When I try to open an xls file, I get this error :
Rhe Microsoft Office 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.
I do several access but I close and dispose the connection all the time. It's on my DEV PC. On the server I get this error : Don't have read/write access on the file. This file is on \networkdisk\directory1\Files
I'll use "ACE.OLEDB" because Jet is not running on x64 server.
Any idea ?
Thanks,
In my case it was a file stream that had not been closed.
in our case, a client uploaded an excel file that is password protected
Am using asp.net's FileUpload control to upload a word file to the server.
I want to encrypt the contents of this file (using our custom encryption API) and then save it in the server.
How do i achieve this?what should be my approach?
Thanks.
Whatever you do on the server side, do realize that while the data is transfering over the wire, it will not be encrypted with your custom api. You will need to upload the file using an ssl connection in order ensure the data transfer is secure.
if you have your own custom encryption API, you should use it to encrypt in a temporary file and then upload the temporary encrypted result, and delete it after upload complete.
The FileUpload control gives you a handle to the file. Read the data from the file stream, encrypt it and write it to a FileStream. If the encryption process is CPU intensive and/or takes a lot of time, save the file in a temp directory and start a new thread that reads the file, encrypts its contents, saves it to a new file and deletes the temp file.
maybe u should write your own encryptor as an app and then decrypt that file on the server
this article could help u : file encrypt / decrypt