ASP.Net MVC Write Memory Stream to Disk?

Hello all,

I have a create PDF method that creates a PDF as a memory stream.   It is used to response out to the browser a PDF doc.   I need a button that is going to on click take that memory stream and write it to a physical file on disk.    In MVC is there anyway to handle this and also somehow alert the user that file is completed?   Hoping in some action result I can do this.   Best case would be showing a processing thing but right now just simply how to handle this.

Thanks all
sbornstein2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Craig WagnerSoftware ArchitectCommented:
Which disk, the web server or the client? If it's the client you can't write to the client's hard drive from your application (imagine the HUGE security hole that would present). If you're sending them a PDF their browser or PDF reader will give them the option to save it.
0
sbornstein2Author Commented:
It will actually save to disk on a network UNC path.   How do I do this async though and know when the file is done saving?
0
silemoneCommented:
there are a few ways to know if a file is finished saving:

If your process sends a success email after a file is uploaded then you can add email to your app and when its received, you will know that its completed saving...

If you have a database that status gets updated when a file has saved, you can check the db for the file status of Success

Otherwise you have to have access to the directory where the file is being saved and as it is being uploaded, it will have a '.part' extension.   You can check directory to see if the file is still in .part format or has changed to .pdf.

These most likely WILL require asynchronous programming - i.e. using Tasks library or some other process/thread oriented methodology to either keep checking db for success or checking directory.

One other methodology is to have a FileSystemWatcher that triggers some action when a new file is created, renamed or changed (these are events for FileSystemWatcher) on the landing directory of the file.  You would possible run it as a service and let it always run and it will do some actions you designate to once the file is there...you would test to see if the file is locked (i.e. test file to see if it can open - in try/catch - if it goes to catch block, it means its not complete yet) on those events.

The type of architecture you use for front end is not really relevant...if u want to tie it to MVC or webpages, or a desktop or just a console up, that would be up to you.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sbornstein2Author Commented:
tx
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.