0

I have an MVC 4 application that generates Excel spreadsheets from a template stored on my shared hosting FTP, but I would like the generated files to be stored in the user's Dropbox folder, not the server. How can I accomplish this using C#?

My files are currently saved as follows:

ExcelPackage p = new ExcelPackage(tempFile);

string newpath = Path.Combine(Server.MapPath("~/Content"), "Invoice.xlsx");
            FileInfo newFile = new FileInfo(newpath);
            p.SaveAs(newFile);

tempFile is the template, which isn't relevant here. This code stores it on the server which I don't want.

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
barnacle.m
  • 2,070
  • 3
  • 38
  • 82
  • 1
    You'll need to take a look at the [Dropbox API](https://www.dropbox.com/developers) to see how to get access to a users dropbox account to upload it from the server on their behalf. – Steven V Sep 09 '13 at 15:13
  • 1
    This answer here seems to indicate what you want: http://stackoverflow.com/a/9660541/1448512 – Lorcan O'Neill Sep 09 '13 at 15:30
  • @LorcanO'Neill Your link is not suitable to a web application – glautrou Sep 09 '13 at 15:33

2 Answers2

3

You can do this by using the DropBox API.

Unfortunately there is no official API for .Net, but you can find some on the Web like:

I let you check how they work and determine which one is more appropriate to your project, but by looking at the DropBox PHP API it doesn't seem very difficult. It is based on HTTP and OAuth.

glautrou
  • 3,140
  • 2
  • 29
  • 34
  • All I want to do is get the location of the dropbox folder on the user's computer, not write directly to the cloud folder. – barnacle.m Sep 09 '13 at 15:28
  • You cannot access to the user's local folders for security reasons, but you can get locations inside the Dropbox folder. If your users are in your company you can create a local script, but not on the Web. – glautrou Sep 09 '13 at 15:31
0

You will not have any C# code running on the client in a web application and very doubtful you'd get the permission in any web application. What you'd might want to consider is offer the user to download the file, suggesting they put it in their dropbox folder.

dove
  • 20,469
  • 14
  • 82
  • 108
  • I may have not explained correctly, see I need to get the users dropbox folder on his/her computer. That way I just save the document to that folder and it gets uploaded automatically. – barnacle.m Sep 09 '13 at 15:22
  • @barnacle.m you will not have the permission to access their local folder. at best you could ask users to provide their dropbox credentials and you could use the dropbox api to write to their cloud which would then obviously sync to their local folder. – dove Sep 10 '13 at 11:54