如何使用C#从NetSuite中的FileCabinet下载文件

let007live4ever

我需要从NetSuite中的FileCabinet下载文本文件。我能够搜索文件夹中的所有文件,并获取文件大小,名称和URL。但是,当我检查'content'属性时,它为NULL。如何在本地下载文件?

我尝试使用URL通过WebClient下载文件,但是它返回403,这很有意义。

        var result = Client.Service.search(fileSearch);            
        var recordList = (Record[])result.recordList;
        if (recordList != null && recordList.Length != 0)
        {
            foreach (var item in recordList)
            {                    
                var file = (com.netsuite.webservices.File)item;                    

                int fileSize = (int)file.fileSize; // Returns the correct file size

                byte[] fileContent = file.content; // NULL reference ??

                Console.WriteLine(file.url + " ==== " + file.name );

                // How to download the File from the url above??

                // Can't do this, 403 error, below client dont use the same security context
                //using (var client = new WebClient())
                //{                        
                //    client.UseDefaultCredentials = false;
                //    client.DownloadFile(baseUrl + file.url, file.name);
                //}
            }
        }

我希望“内容”包含文件内容。

迈克·罗宾斯

执行搜索时,搜索结果不包括文件的内容,但是您确实具有文件ID。以下是NetSuite服务上的扩展方法,可通过其ID获取文件:

public static NetSuite.File GetFileById(this NetSuiteService ns, int fileId)
{
    var file = new NetSuite.File();
    var response = ns.get(new RecordRef()
    {
        type = RecordType.file,
        internalId = fileId.ToString(),
        typeSpecified = true
    });

    if (response.status.isSuccess)
    {
        file = response.record as File;
    }

    return file;
}

var f = ns.GetFileById(3946);
var path = Path.Combine(Directory.GetCurrentDirectory(), f.name);
var contents = f.content;
System.IO.File.WriteAllBytes(path, contents);

Console.WriteLine($"Downloaded {f.name}");

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在C#中从FTPS下载文件

来自分类Dev

如何使用c#名称下载文件?

来自分类Dev

C#如何使用libcurlnet下载文件

来自分类Dev

使用C#在IE 11中自动下载文件

来自分类Dev

如何在SuiteScript中从FileCabinet加载文件

来自分类Dev

使用硒C#,如何在IE11中下载文件?

来自分类Dev

C#中的异步下载文件

来自分类Dev

如何使用C从http下载文件?

来自分类Dev

下载文件C#

来自分类Dev

c#尝试使用WebClient下载文件名中包含特殊字符的文件

来自分类Dev

如何使用WebClient登录“ Flash网站”并使用c#下载文件?

来自分类Dev

如何在C#中下载文件名?

来自分类Dev

等待Selenium和C#中的完成下载文件

来自分类Dev

使用C#从SQL Server下载文件

来自分类Dev

如何使用C#在客户端计算机上下载文件

来自分类Dev

如何使用C Socket编程下载文件

来自分类Dev

下载文件C#的线程

来自分类Dev

从C#的REST服务下载文件

来自分类Dev

如何使用restsharp下载文件

来自分类Dev

如何使用硒下载文件?

来自分类Dev

如何使用锚标记<a>下载文件

来自分类Dev

如何使用jQuery下载文件?

来自分类Dev

如何使用Cowboy下载文件?

来自分类Dev

如何使用Java Spark下载文件?

来自分类Dev

如何使用php下载文件?

来自分类Dev

如何使用jxbrowser库下载文件?

来自分类Dev

如何使用Express从url下载文件?

来自分类Dev

如何使用git从heroku下载文件

来自分类Dev

如何使用JavaScript强制下载文件?