I want to store file on dropbox through sharpbox.I followed their own basic tutorial in which they said to create the token file from dropbox token authorization tool provided in the project itself after installing nuget package but I am unable to generate it.Error 404 occurs.Below is my code which I wrote for creating token file in order to store files on dropbox.In this code following exception
"An unhandled exception of type 'System.IO.IOException' occurred in mscorlib.dll
Additional information: The process cannot access the file 'E:\test.txt' because it is being used by another process"
occurs at Line
var fs = File.Open(@"E:\test.txt", FileMode.Open, FileAccess.Read, FileShare.None).
以下のコードでは、作成したファイルで取得したアクセス トークンの値を書き込もうとしていますが、上記の例外が発生しています。先に進むにはこのファイルが必要なので、正しいトークン ファイルを取得するためにこのコードを修正してください。
これが私のコードです:
using AppLimit.CloudComputing.SharpBox;
using AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CreatingtokenFile
{
class Program
{
static void Main(string[] args)
{
//CloudStorage dropBoxStorage = new CloudStorage();
CloudStorage storageNew = new CloudStorage();
// enter the comsumer key and secret
String ConsumerKey = "**********";
String ComsumerSecret = "**************";
// 0. load the config
DropBoxConfiguration config = DropBoxConfiguration.GetStandardConfiguration();
config.AuthorizationCallBack = new Uri("http://google.com");
// 1. get the request token from dropbox
DropBoxRequestToken requestToken = DropBoxStorageProviderTools.GetDropBoxRequestToken(config, ConsumerKey, ComsumerSecret);
//requestToken = DropBoxStorageProviderTools.GetDropBoxRequestToken(config, ConsumerKey, ComsumerSecret);
// 2. build the authorization url based on request token
String url = DropBoxStorageProviderTools.GetDropBoxAuthorizationUrl(config, requestToken);
////Save token to Session
// HttpContext.Current.Session["requestToken"] = requestToken;
// 3. Redirect the user to the website of dropbox
// ---> DO IT <--
System.Diagnostics.Process.Start(url);
// ---> if not, you will get an unauthorized exception <--
//
//this line does create a file but it's empty, so what we need to do is to save the access token in this file
Stream xmlStream = File.Create(@"E:\test.txt");
//
// 4. Exchange the request token into access token
using (var fs = File.Open(@"E:\test.txt", FileMode.Open, FileAccess.Read, FileShare.None))
{
ICloudStorageAccessToken accessToken = DropBoxStorageProviderTools.ExchangeDropBoxRequestTokenIntoAccessToken(config, ConsumerKey, ComsumerSecret, requestToken);
//ICloudStorageAccessToken accessToken1;
accessToken = storageNew.DeserializeSecurityToken(fs);
storageNew.Open(config, accessToken);
}
}
}
}