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);
}
}
}
}