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);
}
}
}
}
itemImage is just a string - base64.
take that string and do a base64 decode and save that to your local file.
If the search is based on the internal id of the file you want to search, then the following code may help
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);
}
In this code the folder internal id and the file internal id is given as the search parameters. So the file search will be done in the specified file cabinet with specified file id.
The response from netsuite will consist of the internal id, file name, url, folder name etc. The file can be downloaded from the url location.
Related
I need suggestion on getting a list of PDF files from the external storage in android device
1.You could traverse the folder and filter the PDF files:
public void Search_Pdf_Dir(File dir)
{
string pdfPattern = ".pdf";
File[] FileList = dir.ListFiles();
if (FileList != null)
{
for (int i = 0; i < FileList.Length; i++)
{
if (FileList[i].IsDirectory)
{
Search_Pdf_Dir(FileList[i]);
}
else
{
if (FileList[i].Name.EndsWith(pdfPattern))
{
//here you have that file.
}
}
}
}
}
then you could call like Search_Pdf_Dir(Android.OS.Environment.ExternalStorageDirectory);
2.use MediaStore - Uri to query all types of files :
ContentResolver cr = ContentResolver;
Android.Net.Uri uri = MediaStore.Files.GetContentUri("external");
// every column, although that is huge waste, you probably need
// BaseColumns.DATA (the path) only.
string[] projection = null;
string selectionMimeType = MediaStore.Files.FileColumns.MediaType + "=?";
string mimeType = MimeTypeMap.Singleton.GetMimeTypeFromExtension("pdf");
string[] selectionArgsPdf = new string[] { mimeType };
string sortOrder = null;
var allPdfFiles = cr.Query(uri, projection, selectionMimeType, selectionArgsPdf, sortOrder);
while (allPdfFiles.MoveToNext())
{
int column_index = allPdfFiles.GetColumnIndexOrThrow(MediaStore.Images.Media.InterfaceConsts.Data);
string filePath = allPdfFiles.GetString(column_index);//the pdf path
}
I am able to generate the hash value of each respective file in Google Drive. My question is how do I store these hashes in like a hashtable or hash set so that I can perform comparison of hash later so that I can remove the duplicated hashes.
public static List<GoogleDriveFiles> GetDriveFiles()
{
DriveService service = GetService();
// define parameters of request.
FilesResource.ListRequest FileListRequest = service.Files.List();
//listRequest.PageSize = 10;
//listRequest.PageToken = 10;
FileListRequest.Fields = "nextPageToken, files(id, name, size, createdTime, md5Checksum, fileExtension, modifiedTime, mimeType)";
//get file list.
IList<Google.Apis.Drive.v3.Data.File> files = FileListRequest.Execute().Files;
List<GoogleDriveFiles> FileList = new List<GoogleDriveFiles>();
if (files != null && files.Count > 0)
{
foreach (var file in files)
{
GoogleDriveFiles File = new GoogleDriveFiles
{
Id = file.Id,
Name = file.Name,
Size = file.Size,
CreatedTime = file.CreatedTime,
MD5hash = file.Md5Checksum,
Extension = file.FileExtension,
ModifiedTime = file.ModifiedTime,
MimeType = file.MimeType,
};
FileList.Add(File);
}
}
return FileList;
}
I am unsure how should I approach this problem. Am I able to compute a hashtable in that function or should I build another constructor.
I am new to using acumatica web service. is it possible to upload a document/ file in specific screen as attachment like business account attachment.
eg. below screen in which we add manually.
I find the solution and posted to help anyone.
To upload any file we must convert that file into bytes and submit bytes which convert your file.
//Get bytes of file
byte[] filedata;
using(System.IO.FileStream file =
System.IO.File.Open(#"D:\Test.pdf",System.IO.FileMode.Open))
{
filedata = new byte[file.Length];
file.Read(filedata,0,filedata.Length);
}
// Import Data Now to Business Account
BAccount.CR303000ImportResult[] lstObjContent = context.CR303000Import
(
new BAccount.Command[]
{
// Must Pass BusinessAccount in which we want to update or add data
new BAccount.Value { Value="XXXXXX",LinkedCommand=objContent.AccountSummary.BusinessAccount},
new BAccount.Value { Value="TestValue123",LinkedCommand=objContent.AccountSetup.CurrentMethod},
new BAccount.Value { FieldName="NameOfFileWithExtension",LinkedCommand=objContent.AccountSummary.ServiceCommands.Attachment},
objContent.Actions.Save
},null,new string[][] { new string[] { Convert.ToBase64String(filedata) },new string[] { Convert.ToBase64String(filedata) },}
,false,false,true
);
Even the below code works. Verified in version 18R1.
var content = _context.CR306000GetSchema(); _context.CR306000Clear();
var commands = new List();
ReqParameter(content, ref commands);
commands.Add(content.Actions.Save);
commands.Add(content.CaseSummary.CaseID);
var orderResults = _context.CR306000Submit(commands.ToArray());
private static void ReqParameter(CR306000Content content, ref List<Command> cmds)
{
if (cmds == null) throw new ArgumentNullException("cmds");
byte[] filedata= null;
Uri uri = new Uri("https://acmdev.baccahq.com/Icons/login_bg5.jpg"); // change the required url of the data that has to be fetched
if (uri.IsFile)
{
string filename = System.IO.Path.GetFileName(uri.LocalPath);
filedata = System.Text.Encoding.UTF8.GetBytes(uri.LocalPath);
}
if (filedata == null)
{
WebClient wc = new WebClient();
filedata = wc.DownloadData(uri);
}
cmds = new List<Command>
{
//Case Header Details
new Value { Value="<NEW>",LinkedCommand = content.CaseSummary.CaseID},
new Value { Value="L41",LinkedCommand = content.CaseSummary.ClassID},
new Value { Value="ABCSTUDIOS",LinkedCommand = content.CaseSummary.BusinessAccount, Commit = true},
new Value { Value="Test subject created from envelop call 11C",LinkedCommand = content.CaseSummary.Subject},
// body of the case
new Value{Value= "Body of the content for created through envelop call 11B", LinkedCommand = content.Details.Description},
//Attaching a file
new Value
{
Value = Convert.ToBase64String(filedata), // byte data that is passed to through envelop
FieldName = "Test.jpg",
LinkedCommand =
content.CaseSummary.ServiceCommands.Attachment
},
};
}
I am refactoring a section of my app to save a file to the Db in a bit field. In other places I have used the SqlCommand method but here I would like to latch on to my existing EF procedure, for many reasons not apparent. The uploader works fine but it breaks down when it gets to the LINQ. When I query the Db, instead of the usual "0x25504462D..." in the bit field, I get simply "0x". Attempting to view the file gets a message "file is empty". Am I close? The other fields are inserted perfectly, and there are no errors in the insert process. How do I "feed" the file to the fileUpload? Please advise.
HttpPostedFileBase file = Request.Files[inputTagName];
FileUpload fileUpload = new FileUpload();
using (DBEntities ode = new DBEntities())
{
(check if file exists...)
else
{
MyModels.File newfile = new MyModels.File();
newfile.ID = Guid.NewGuid();
newfile.Name = fn;
newfile.VirtualPath = filePath;
newfile.DateTimeUploaded = DateTime.Now;
newfile.binFile = fileUpload.FileBytes;
ode.AddToFiles(newfile);
}
ode.SaveChanges();
}
You could try getting the `byte[]' value of the uploaded file.
HttpPostedFileBase file = Request.Files[inputTagName];
var uploadedFile = new byte[file.InputStream.Length];
using (DBEntities ode = new DBEntities())
{
(check if file exists...)
else
{
MyModels.File newfile = new MyModels.File();
newfile.ID = Guid.NewGuid();
newfile.Name = fn;
newfile.VirtualPath = filePath;
newfile.DateTimeUploaded = DateTime.Now;
newfile.binFile = uploadedFile;
ode.AddToFiles(newfile);
}
ode.SaveChanges();
}
After much lamenting and gnashing of teeth (and encouragement from #denchu) it was apparent I needed to read the data:
HttpPostedFileBase file = Request.Files[inputTagName];
//var uploadedFile = new byte[file.InputStream.Length];
BinaryReader br = new BinaryReader(file.InputStream);
byte[] uploadedFile = br.ReadBytes(file.ContentLength);
using (DBEntities ode = new DBEntities())
{
(check if file exists...)
else
{
MyModels.File newfile = new MyModels.File();
newfile.ID = Guid.NewGuid();
newfile.Name = fn;
newfile.VirtualPath = filePath;
newfile.DateTimeUploaded = DateTime.Now;
newfile.binFile = uploadedFile;
ode.AddToFiles(newfile);
}
ode.SaveChanges();
}
I'm generating pdf from view using ROTATIVA
public ActionResult StandartPDF()
{
var makeCvSession = Session["makeCV"];
var something = new Rotativa.ViewAsPdf("StandartPDF", makeCvSession) { FileName = "cv.pdf" };
return something;
}
using that code user can download it. But at first I want to it on server. How can I do that?
I solved that using SaveOnServerPath property in Rotativa class
public ActionResult StandartPDF()
{
var makeCvSession = Session["makeCV"];
var root = Server.MapPath("~/PDF/");
var pdfname = String.Format("{0}.pdf", Guid.NewGuid().ToString());
var path = Path.Combine(root, pdfname);
path = Path.GetFullPath(path);
var something = new Rotativa.ViewAsPdf("StandartPDF", makeCvSession) { FileName = "cv.pdf", SaveOnServerPath = path };
return something;
}