0

I am trying to upload a Word Document to my personal box account using Box Windows SDK V2 using the following code.

using (Stream s = new FileStream("C:\\word.docx",
                 FileMode.Open, FileAccess.Read,
                 FileShare.ReadWrite))
                {
                    MemoryStream memStream = new MemoryStream();
                    memStream.SetLength(s.Length);
                    s.Read(memStream.GetBuffer(), 0, (int)s.Length);

                    BoxFileRequest request = new BoxFileRequest()
                    {
                        Parent = new BoxRequestEntity() { Id = "0" },
                        Name = TxtSaveAS.Text

                    };
                    BoxFile f = await Client.FilesManager.UploadAsync(request, memStream)

The document gets uploaded successfully in root folder but the problem is, the extension of document is set to "File" (which is not previewed by Box because of having unsupported extension, neither it gets the icon of word document) rather than "docx" though it still gets open correctly in Microsoft word. How to upload file using box windows sdk with respective extensions. suggestions are greatly welcomed.

Muhammad Murad Haider
  • 1,357
  • 2
  • 18
  • 34

1 Answers1

1

In order to upload the file with the correct extension, simply append the extension to the Name.

BoxFileRequest request = new BoxFileRequest()
{
  Parent = new BoxRequestEntity() { Id = "0" },
  Name = TxtSaveAS.Text + ".docx"
};    
John Hoerr
  • 7,955
  • 2
  • 30
  • 40
  • @ John Hoerr: yup, i did exactly like that and it worked as required. Sorry, couldn't update it. Can't mark it as an answer (didn't get) enough reputation for this but it's the correct answer. – Muhammad Murad Haider May 26 '14 at 14:52