首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法通过sharpbox在dropbox上创建用于文件存储的令牌文件。发生IO异常

无法通过sharpbox在dropbox上创建用于文件存储的令牌文件。发生IO异常
EN

Stack Overflow用户
提问于 2014-07-21 00:29:41
回答 1查看 436关注 0票数 0
代码语言:javascript
复制
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). 

在下面提供的代码中,我试图写入在创建的文件上获得的访问令牌值,但异常即将到来,请更正此代码以获得正确的令牌文件,因为我需要此文件进一步进行。

下面是我的代码:

代码语言:javascript
复制
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);
            }


        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2014-07-21 02:52:19

您将打开以下行中的文件:

代码语言:javascript
复制
Stream xmlStream = File.Create(@"E:\test.txt");

然后再试着在这里打开它:

代码语言:javascript
复制
File.Open(@"E:\test.txt", ...)

因此,正如错误所述,您正在尝试打开已在使用中的文件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24852539

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档