2

I need to download JPG file from FileCabinet in NetSuite. For that I know the file name, so I searched file and assigned to FileObject. I got the object right, but got NULL content. I am providing here some code. Can anybody point out the error or any missing step here? Thank you.

var result = _service.search(flSearch);
if (result.totalRecords > 0)
{
    recordList = result.recordList;
    Record[] records = new Record[recordList.Length];
    for (int j = 0; j < recordList.Length; j++)
    {
        if (recordList[j] is File)
        {
            File itemImage = (File)(recordList[j]);            
            byte[] data;
            data = new Byte[(int)itemImage.fileSize];
            data = itemImage.content;  //Here getting NULL value
            FileStream inFile;
            using (inFile = new FileStream("newImage.jpg", FileMode.Create, FileAccess.Write))
            {
                inFile.Write(data, 0, data.Length);
            }
        }
    }
}
4

2 回答 2

2

itemImage 只是一个字符串 - base64。

获取该字符串并进行 base64 解码并将其保存到本地文件中。

于 2012-11-08T01:14:04.583 回答
1

如果搜索基于您要搜索的文件的内部 id,那么以下代码可能会有所帮助

        var service = LoginNetSuite();
        Tuple<string, string> fileContent = null;

        FileSearch fileSearch = new FileSearch();
        FileSearchBasic fileSearchBasic = new FileSearchBasic();

        // Specify the folder in which the search is to be done.
        SearchMultiSelectField folderFilter = new SearchMultiSelectField();
        folderFilter.@operator = SearchMultiSelectFieldOperator.anyOf;
        folderFilter.operatorSpecified = true;
        RecordRef[] folder = new RecordRef[1];
        folder[0] = new RecordRef();
        folder[0].internalId = "78990"; // 78990 => Internal id of the folder.
        folderFilter.searchValue = folder;
        fileSearchBasic.folder = folderFilter;

        // Specify the file internal id.
        SearchMultiSelectField fileFilter = new SearchMultiSelectField();
        fileFilter.@operator = SearchMultiSelectFieldOperator.anyOf;
        fileFilter.operatorSpecified = true;
        RecordRef[] rec = new RecordRef[1];
        rec[0] = new RecordRef();
        rec[0].internalId = "345656"; // 345656 => Internal id of the file.
        fileFilter.searchValue = rec;

        fileSearchBasic.internalId = fileFilter;
        fileSearch.basic = fileSearchBasic;

        var result = service.search(fileSearch);
        var recordList = (Record[])result.recordList;
        if (recordList != null && recordList.Length != 0)
        {
            var file = (File)result.recordList.First();
            fileContent = new Tuple<string, string>(file.url, file.name);
        }

在此代码中,文件夹内部 ID 和文件内部 ID 作为搜索参数给出。所以文件搜索将在指定文件id的指定文件柜中进行。来自 netsuite 的响应将包括内部 id、文件名、url、文件夹名等。文件可以从 url 位置下载。

于 2016-12-14T07:25:57.933 回答