Welcome to the new Box Support website. Check out all the details here on what’s changed.

How to Use OAuth2 Authentication Method In .Net

New post



  • jcleblanc

    Hi ,


    It's a little bit dated, but I have this .Net example that I prepared a while back that should give you info on how to set up a sample app.


    - Jon

    Comment actions Permalink
  • Attiliopasquale

    those example didn't work.

    I explain:

    var task = Task.Run(

    async () =>
    bool ret = false;
    BoxConfig config = new BoxConfig(CLIENTID, CLIENTSECRET, new Uri(""));
    var session = new OAuthSession(APPTOKEN, "N/A", 3600, "bearer");
    var client = new BoxClient(config, session);

    using (FileStream fileStream = new FileStream(filePath, FileMode.Open))
    BoxFileRequest requestParams = new BoxFileRequest()
    Name = Path.GetFileName(filePath),
    Parent = new BoxRequestEntity() { Id = "0" }

    BoxFile file = await client.FilesManager.UploadAsync(requestParams, fileStream);
    ret = File.Exists(filePath);
    return ret;

    return task.Result;


    This is the code in c#

    On task.Wait() it pops with error:


    Messaggio=Si sono verificati uno o più errori.
    Analisi dello stack:
    in System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
    in System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
    in System.Threading.Tasks.Task.Wait()
    in Cloud.Box.uploadFile(String filePath) in E:\Lirasoft\iCloud\Box.cs: riga 53
    in TestCloud.Form1.button5_Click(Object sender, EventArgs e) in E:\Lirasoft\TestCloud\Form1.cs: riga 140
    in System.Windows.Forms.Control.OnClick(EventArgs e)
    in System.Windows.Forms.Button.OnClick(EventArgs e)
    in System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
    in System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
    in System.Windows.Forms.Control.WndProc(Message& m)
    in System.Windows.Forms.ButtonBase.WndProc(Message& m)
    in System.Windows.Forms.Button.WndProc(Message& m)
    in System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
    in System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
    in System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
    in System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
    in System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
    in System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
    in System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
    in System.Windows.Forms.Application.Run(Form mainForm)
    in TestCloud.Program.Main() in E:\Lirasoft\TestCloud\Program.cs: riga 19

    Eccezione interna 1:
    BoxSessionInvalidatedException: Generata eccezione di tipo 'Box.V2.Exceptions.BoxSessionInvalidatedException'.

    Comment actions Permalink
  • Attiliopasquale

    in apptoken i put developer token that i read lives few second. How to have apptoken instead any time i want to make a call ?

    Comment actions Permalink

Please sign in to leave a comment.