Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
File 无法通过sharpbox为dropbox上的文件存储创建令牌文件。发生IO异常_File_Exception_Token_Dropbox_Sharpbox - Fatal编程技术网

File 无法通过sharpbox为dropbox上的文件存储创建令牌文件。发生IO异常

File 无法通过sharpbox为dropbox上的文件存储创建令牌文件。发生IO异常,file,exception,token,dropbox,sharpbox,File,Exception,Token,Dropbox,Sharpbox,在下面提供的代码中,我试图写入在创建的文件上获得的访问令牌值,但出现了上述异常。请更正此代码以获取正确的令牌文件,因为我需要此文件以继续 这是我的密码: 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 provid

在下面提供的代码中,我试图写入在创建的文件上获得的访问令牌值,但出现了上述异常。请更正此代码以获取正确的令牌文件,因为我需要此文件以继续

这是我的密码:

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


        }
    }
}
然后您尝试在此处再次打开它:

Stream xmlStream = File.Create(@"E:\test.txt");

因此,正如错误所说,您正在尝试打开一个已经在使用的文件。

任何代码如果不尝试打开同一个文件两次或至少在两次打开之间关闭该文件。
File.Open(@"E:\test.txt", ...)