gpt4 book ai didi

c# - C# 中的 Netsuite Web 服务

转载 作者:行者123 更新时间:2023-11-30 15:02:34 24 4
gpt4 key购买 nike

我正在使用 C# 程序将图像文件上传到 netsuite。谁能帮我调用 netsuite 脚本(写在java 脚本)在 C# 中,因为我只能在 netsuite 脚本中找到上传 api。是否有任何网络服务或功能 在 netsuite 中上传图片文件到 netsuite 中?

最佳答案

您可以直接使用 SuiteTalk 上传文件。下面的示例是用 C# 编写的。

像这样调用下面的方法:

uploadFile(@"SERIAL_NUMBERS.csv", "csv", "123456");

方法:

public static void UploadFile(string filename, string filetype, string folderId)
{

var sFileName = filename;

var sNsFileName = filename;

var sFileType = filetype;

var sFolderId = folderId;

var uploadFile = new com.netsuite.webservices.File { attachFromSpecified = true, attachFrom = FileAttachFrom._computer };

if (sFolderId != null)
{
var folderRef = new RecordRef { internalId = sFolderId };
uploadFile.folder = folderRef;
}

// Specify the NetSuite filename
if (sNsFileName != null)
uploadFile.name = sNsFileName;

uploadFile.fileTypeSpecified = true;
if (sFileType != null)
{
if (sFileType.Trim().ToLower().Equals("plaintext"))
uploadFile.fileType = MediaType._PLAINTEXT;
else if (sFileType.Trim().ToLower().Equals("image"))
uploadFile.fileType = MediaType._IMAGE;
else if (sFileType.Trim().ToLower().Equals("csv"))
uploadFile.fileType = MediaType._CSV;
else
uploadFile.fileType = MediaType._PLAINTEXT;
}
else
uploadFile.fileType = MediaType._PLAINTEXT;

uploadFile.content = LoadFile(sFileName);

// Invoke add() operation to upload the file to NetSuite
var response = Service.add(uploadFile);

// Process the response
if (response.status.isSuccess)
{
Console.WriteLine(
"\nThe file was uploaded successfully:" +
"\nFile Record key=" + ((RecordRef)response.baseRef).internalId +
"\nRenaming file");
}
else
{
Console.WriteLine("The file was not uploaded. Please notify the NetSuite team of the following error:");
DisplayError(response.status.statusDetail);

}
}

private static byte[] LoadFile(String sFileName)
{
byte[] data;

try
{
FileStream inFile;
using (inFile = new FileStream(sFileName, FileMode.Open, FileAccess.Read))
{
data = new Byte[inFile.Length];
inFile.Read(data, 0, (int)inFile.Length);
}
}
catch (Exception ex)
{
// Error creating stream or reading from it.
Console.WriteLine(ex.Message);
return null;
}

return data;
}

关于c# - C# 中的 Netsuite Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12498131/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com