Deleting file from remote machine using ASP.NET - asp.net

My page shows a grid with two column. 1st column has the hyperlink which when clicked opens the associated pdf (hosted on remote machine) in a new window. Internally I think the pdf is downloaded to the client computer's machine and he/she sees the cached copy. 2nd column has a delete button which when clicked deletes the associated pdf.
My problem is that if the pdf is currently open in the window, the delete button fails to delete the pdf because of sharing violation. I can go ahead and close the pdf and this allows the delete button to work fine.
I was wondering if I should be getting a sharing violation error since the client sees the cached copy of the pdf and not the original pdf?
Also, is there a way in IIS to release remote resources? Which might help in deleting the remote pdf even if its open on client machine?

Related

Word 16 document is opening in Locked mode

i'm Opening Word File from my Application in HTTP Path
i.e. http:\Server\SiteName\TempFiles\filename.docx
Word File Showing message as "READ ONLY : This Document is Lock for Editing by another user"
because of this my macro didn't work
Protection = ActiveDocument.ProtectionType
If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
ActiveDocument.Unprotect "password"
WordBasic.AcceptAllChangesInDoc
ActiveDocument.Protect Protection, False, "password"
Call updateCustomVariables
ActiveDocument.Saved = True
Exit Sub
End If
every thing is working fine
and still working fine on office (Word) 13,10 machines
this problem suddenly start from last 3- 4 days
i'm getting error as Command failed (Run time Error 4198) for office 16 for ActiveDocument.Unprotect "password" line
no office Updates
no windows update
please help..
Check trusted Location Setting of Word i.e. Allow documents from Network to be trusted
disable all Protected View options
I know this isn't an answer but I'm new here and can't comment yet ;)
Got the same problem with one of our customers. Issue appeared in the latest Office 365 monthly rollout (16.0.11901.20264) a few days ago. The semi-annual version (16.0.11328.20362) doesn't have the issue. Our files are served using a URL with parameters. With previous versions of office it displays Read Only in the title bar but allows the user to edit the content.
With the new monthly version there is a read-only message that displays under the ribbon with a link to Save As. User cannot change the document content unless he saves the file locally. Even worse Word makes requests without the parameters so our code abends. I changed the code locally to put the parameter information in the path and I can open the document. But it still says that it's locked and the user can't edit the content.
We open and manage documents them using a VSTO side panel so we don't need to save them using the Save button. The application has it's own Save button that retrieves the updated content, saves it using an AJAX call and closes Word. Nice change of behavior from MS ;)

all pdfs generating correctly using http handler , except for one in web application

I am trying to generate pdf on clicking on url for different invoices on front end, using httphandler in asp.net web forms in the back end. The pdf generates well for all the invoices except for one, ON LIVE environment.
It opens a dialog box saying:
"Adobe Reader could not open '_XYZ__.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded)"
While , when I try to replicate the same on my Dev / test enviroment , all the pdfs generate properly for all the invoices.
Hence, I am unable to debug the issue on Live. How do I solve it and what could be the reason. Please guide.
Thanks

How do I identify respective file viewer is present in client machine?

We have developed Asp.net web application, Here we have uploaded the DWFX file. In one if the UI we have managed the uploaded file.
In this ui user will select the file name then we have provided two options like download and view, When user clicks the "download" option then file will be downloaded via browser.
When user clicks the "View" button then we have to open the DWFX file via browser. if client has installed the DWFX viewer in his machine then it is works fine otherwise it shows the blank browser screen, Instead of showing the blank screen System should tell to user like "DWFX viewer not installed this machine".
How to identify the DWFX viewer installed or not in client machine? or how to achive this requirement.
Thanks
Mayil.M
Short answer, You don't. You just have display instruction on your site that they need the free DWG TrueView software from Autodesk.
Long answer, you write an ActiveX control or a Java Applet that check if the required software if already install. And the user would have to grant your little utility the proper permission.

How does one print external files (XLS, PDF, DOCX, etc) from ASP.NET?

We have an application in classic ASP that allows user to 'attach' files to information. These can be PDFs, spreadsheets, Word documents, etc.
In the new ASP.NET version, one requested option was for a "Print All" (one user has a situation where there are 34 attached files and, in the current system, she has to open and print each one individually).
The files are kept in a separate directory - not embedded in the database. The database simply contains an ID number and the file's extension so the application would then go out and open "2182.xls" if the user wanted to see it (which would open an Excel window in that case).
Is there a way to send a file to a printer when all you have is the fully qualified filename? (Which I could presumably repeat 34 times in the above example)
Thanks in advance.
Remember that your asp.net code runs on the web server. It's not running on the client computer and has no knowledge of what printers (if any!) are installed there. That's just the way the web works; by design, all a web app can do is open the print dialog for the current page. Anything more, and hackers would use our web browsers for the same kind of spam you get at a fax machine.
That said, there might be some things you can do:
Add an activex control, flash app, silverlight app, firefox plugin, or other plugin code to support the feature.
Render all the attachments on the server into one html document with appropriate styles and javascript so it prints correctly and prompts the user on load.
If this if for a local intranet site (as opposed to public internet) where you have special knowledge of what printers are available for the current user, you could setup all the printers on your server and have it print to the correct location on behalf of the user.

How do you show a preview image when allowing file uploads in ASP.NET?

Here is the functionality I want:
User selects an image from their machine, hits an Upload button (or better yet the following fires on the onchange event of the file input), and is able to see a preview of the image they are about to upload.
Here is the current workflow I am using, but it seems suboptimal:
I have an image control, a file input control and a submit button control. When the submit button is clicked, the codebehind handles the OnClick event and loads the image from the file input element. It then stores it into a temporary folder on the web server and sets the image control's ImageUrl to point to it.
This works, but results in me having to do a lot of janitorial duty in cleaning up these temporary images. Is there a cleaner workflow for doing this?
If you have memory to burn:
cache the image bytes in memory
set your ImageUrl to an image handler (.ashx) with some sort of cache identifier
serve the image bytes from cache
if the user cancels or leaves, discard the cached bytes
if the user accepts, write the cached bytes to their final destination
You should upload and rename the image to match some sort of ID for your current record. Then, when you upload a new file, delete any old ones first, all in the codebehind.
If you are only showing a thumbnail, you should try to use an image library to resize the image before saving. This will save on bandwidth and storage space.
I am assuming that the problem you are trying to solve is for your application to have the ability to preview the image before the user commits to that image. Your current approach has many advantages but one disadvantage is orphaned image files in a temporary directory if the user previews several images before committing or abandons the operation all together.
I've noticed several popular social networking sites using a different approach. Basically, a Java applet is used to do the preview operation on the user's local machine. The only file uploaded to the server is what the user commits to. That approach solves the problem that you are running into; however, it introduces the new problem of requiring Java to be installed on the local machine and integrated with the web browser.
you can create a small executable to delete files on* that temporary folder, and attach it to a schedule task so it will clean your temp. folder once in a while. But I don't know if you're hosting on a dedicated server or shared hosting because with shared hosting, this doesn't work
and is able to see a preview of the image they are about to upload
...
When the submit button is clicked, the codebehind handles the OnClick event and loads the image from the file input element. It then stores it into a temporary folder on the web server and sets the image control's ImageUrl to point to it.
Imagine this conversation:
Jim: I don't know if I can afford to drive my car to work today.
Bob: Why don't you just drive to work? When you pay for it, you'll know if you can afford it or not!
Jim: Awesome!
You've just uploaded the file to show them the preview of the file they're about to upload...
While this will undoubtedly work fine if your users are uploading small images over fast connections, when someone tries to upload a 3 meg JPEG over a slow connection, and then wonders why their webpage locked up from selecting a file (they didn't even press submit remember, so you've effectively locked them up 'randomly'), you may wish to re-evaluate this as a solution.
To actually display the image before it gets uploaded, you will need to use some kind of flash or silverlight object (or perhaps a java applet) which can produce a thumbnail of the local file on the user's local disk, before it gets sent to the server. As ugly as this may sound, there literally is no way to do it without some client side plugin.

Resources