Can I use HTTP request and receive response with Excel add-in? - web-scraping

I have a download button and it will save excel file where user selects.
And it's working correctly.
Now I want to check if there is already file exists where user saved last time when user clicks button again.
I think this is related with Web API or OS file managing system.
What I want is like this:
If file exits, just update it, not show save-as dialog again.
But if user deleted or renamed, it will shows save-as dialog again.
Please help me how can I handle this.

Related

Looking for a way to track a True Download of a file, not just the fact that they clicked on a file link

As I understand it, when a link to a file is clicked in the browser, the file is silently downloaded to a temporary directory on the computer. Then the prompt is displayed which shows Open, Save, Cancel... Then if the user clicks Save, they are prompted to save it somewhere, and finally the file is basically transferred to that location when confirmed.
Assuming that is correct, I'm looking for a way to determine if the user actually downloaded the file. So basically determine if they clicked the Save button.
The bit of research that I've done leads me to believe this is not possible, because there is no standardized way of capturing that event, however I could be wrong. And the only possible solution I can come up with is to create an actual client application. Any thoughts on that?
Also, if there are any other off the wall ideas, I'm open to those as well.
And in case it makes a difference, I'm working within an ASP.NET environment.
How about turning this whole problem around and audit the file that actually being downloaded. You can turn on file/folder auditing and capture onlyt the success and failures of the IIS process. Then correlate the audit event with the pieces parts in the IIS log to get the particulars of who actually downloaded the file.
Just my $0.02 YMMV

Deleting file from remote machine using 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?

Do when browser is closed

I know this is stupid question, but will solve my doubts.
I am implementing a web application in ASP.NET MVC 4,in which user has to upload some document.I have a view where user has to upload file, write title,description in text boxes.I will make file upload as ajax and after its submission, user has to write titles etc.m then submit.
I want to know that this may happen that user will upload file using ajax only and then close the window.This way the file has been upload ,but has no use.
So, I want to ask that can it be possible that in such cases , file is deleted from the server as well or there can be other similar solution?
Thanks ,
I think it's better to insert a record on database at upload times, which indicates which files are useful and which have to be deleted, then you can write a service that execute for example every one hour to delete useless files.

ASP.NET - Disappearing session variables

I am working a current web application for a client and I am having some trouble with session variables disappearing on me. I will try and set up a good description of the scenario as best I can. It does not happen on any page other than the page I created to allow users to modify the strings stored in a resource file.
It shows up WHEN:
Users navigate to the page, select a resource file from a list and click edit a first time. The page loads the file into a gridview and allows them to edit it. At this point the session variables are being saved a reloaded correctly upon all postbacks. NOW, they click the save button at the bottom to write the resource file to the filesystem (App_LocalResources). They select a new file from the list, attempt to load it and this time the session variables are cleared out and it redirects them to the login page because it does not know there user information.
Additinal details:
It only happens when they click a save button which in turn calls my procedure to write to the resource file.
I am not really doing much in the save function besides writing to a resource file located in App_LocalResources and for some reason this clears out my session variables.
The session variable in question is there user information, which I attempt to get as the very first thing in a page_load method.
This session information is also executed upon every postback via the page_load method.
Thanks everyone, I hope I described this well enough.
The IIS will reset the application when you change files in the directory associated with the application. Resetting the application will make you lose memory-sessions.
You could put the resource file outside the directory. Or use a stateserver for sessions.

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