Hyperlink to open/download a File (Acumatica) - acumatica

Is there any way to make a hyperlink to a file that will open its contents or download it from the table it belongs? (In a sense, do exactly the same thing as AllowEdit but open/download the file instead.) Example:
Where the Default Specification files are from files found on the customer:
Please note that what displays is the comment of the file. If anyone has any suggestions on how to display the file name instead, that would be appreciated as well.

You can get the filename like this:
UploadFileMaintenance uploadFileMaintenance = PXGraph.CreateInstance<UploadFileMaintenance>();
foreach (Guid note in PXNoteAttribute.GetFileNotes(cache, dacRecord))
{
FileInfo file = uploadFileMaintenance.GetFileWithNoData(note);
PXTrace.WriteInformation(file.Name);
}
To download the file, create a DAC field of string type. You can initialize the string to the file name in the FieldDefaulting or FieldSelecting event. Declare an Action and use the LinkCommand attribute in the ASPX file to make that field control a link.
In that Action event handler, you can redirect the browser to the file in order to download/open it:
UploadFileMaintenance uploadFileMaintenance = PXGraph.CreateInstance<UploadFileMaintenance>();
Guid[] notes = PXNoteAttribute.GetFileNotes(cache, dacRecord);
if (notes != null && notes.Length > 0)
{
FileInfo downloadFile = uploadFileMaintenance.GetFile(notes[0]);
if (downloadFile != null)
{
throw new PXRedirectToFileException(downloadFile.UID, true);
}
}

Related

How to load a txt file in MVC 5 respecting indentation and feed lines?

I am trying to load a text file in MCV5, I saw this piece of code works well
public ActionResult ReleaseNotes()
{ var fileContents = System.IO.File.ReadAllText(Server.MapPath(#"~/App_Data/ReleaseNotes.txt"));
return Content(fileContents); }
but I get something like:
Fixed an error in the user information tool introduced in 3.7.3--------------------------v 03.07.03--------------------------- Change 'Last Logon' to 'Last Connection' in the top right navigation web menu- Disable Shared Configuration admin page, when Shared Configuration feature is deactivated
instead of respecting the indentation and the feed lines of the original format
Fixed an error in the user information tool introduced in 3.7.3
--------------------------v 03.07.03---------------------------
Change 'Last Logon' to 'Last Connection' in the top right navigation web menu- Disable Shared Configuration admin page, when Shared Configuration feature is deactivated.
I have tried many solutions like:
public string ReleaseNotes()
{
string line,returnline="";
// Read the file and display it line by line.
System.IO.StreamReader file =
new System.IO.StreamReader(#"~\App_Data\ReleaseNotes.txt");
while ((line = file.ReadLine()) != null)
returnline = returnline + line + "\t\n";
file.Close();
return returnline;}
Do you know if there is a special class that manages only text files and respects the original format ?
thanks and Regards,
You must modify the controller and the view using a ViewBag to export the datas like that
In the controller
string line;
System.IO.StreamReader file = new System.IO.StreamReader(#"your file txt");
var fileLines = new List<string>();
while ((line = file.ReadLine()) != null)
{
fileLines.Add(line);
ViewBag.File = fileLines;
return View();
In the View (cshtml file)
#{
string line;
foreach (var item in ViewBag.File)
{
<p>#item</p>
}}
It should work properly

Renamed the "Modify By" field after using Elevated Mode

I'm currently facing to an issue using the Elevated Mode used in a Feature.
I have created a custome SharePoint security role (contribute role without the Delete right).
The goal of my SharePoint feature is the following:
When uploading a file to a SP Site, the name of the file needs to be renamed using the meta-data's selected. When uploading a file, a second form is asking the user to defined 3 or 4 meta-data's.
To rename the file, i have developed the following code:
Public override void ItemAdded(SPItemEventProperties properties)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
CallFunctionToUpdate();
});
}
Public override void ItemUpdated(SPItemEventProperties properties)
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
CallFunctionToUpdate();
});
}
Public void CallFunctionToUpdate()
{
try
{
this.EventFiringEnabled = false;
using (SPWeb newWeb = newSite.OpenWeb(_properties.RelativeWebUrl))
{
SPListItem item = newWeb.Lists[_properties.ListId].GetItemById(_properties.ListItem.ID);
newFileName = FilenameManagementHelper.GenerateFilename(properties.ListItem);
currentName = properties.ListItem["Name"].ToString();
var extension = Path.GetExtension(currentName);
if (item["Title"] == null || item["Title"].ToString() != newFileName)
{
item["Title"] = newFileName;
item["Editor"] = new SPFieldUserValue(properties.OpenWeb(), properties.OpenWeb().CurrentUser.ID, properties.OpenWeb().CurrentUser.LoginName);
item.SystemUpdate();
}
if (currentName.Substring(0, currentName.Length - extension.Length) != newFileName)
{
SPList list = newWeb.Lists[_properties.List.Title];
string destUrl = list.RootFolder.Url + "/" + newFileName + extension;
SPFile fileToMove = list.Items[_properties.ListItemUniqueId].File;
SPFolder folder = newWeb.GetFolder(list.RootFolder.Url);
byte[] bin = fileToMove.OpenBinary();
folder.Files.Add(destUrl, bin, fileToMove.Properties, true);
fileToMove.Delete(); newWeb.Lists[list.RootFolder.Url].Update();
}
}
}
catch (Exception ex)
{
DocumentDiagnosticService.LogError(CategoryID.Error, string.Format("Error {0} for the file name - {1}", ex.Message, currentName));
}
finally
{
this.EventFiringEnabled = true;
}
}
Before renaming the file name, I'm updating the field (meta-data's) title and Editor. The second step will move the file (with the meta-data's and the history associated to the uploaded file)
I'm using the Elevated Mode because the user with a restricted Security role cannot delete. In the code developed I'm moving the file renamed and deleting the old file uploaded.
I found that approach because I need to keep the versioning. Updating directly the name of the file (like for the title) is not allowed and that's losing the history. Ex: A file will be uploaded, the name of the file will be updated using the Meta-data's. For the first version, there is no issue. Uploading a second file with the same meta-data's as there is already an existing file with the same name, that will generate an error. Using the Files.Add, that will oerride the current file and will keep the history.
My issue in this case: When the user is uploading the file, the fields Title and Editor are correctly replaced. Than is moving the file, renaming the field Name and deleting the old version. At this moment, the Modify by field is coming the SharePoint Sys Admin all the time.
How can i keep the Modifiy by with the name of the person who is uploading the file ?
EDIT:
Using the following code:
SPList list = newWeb.Lists[_properties.List.Title];
string destUrl = list.RootFolder.Url + "/" + newFileName + extension;
SPFile fileToMove = list.Items[_properties.ListItemUniqueId].File;
SPFolder folder = newWeb.GetFolder(list.RootFolder.Url);
byte[] bin = fileToMove.OpenBinary();
folder.Files.Add(destUrl, bin, fileToMove.Properties, true);
fileToMove.Delete();
Allow me to move the file with the meta-data's selected during the upload. I still have the versioning if a current version is already uploaded BUT the Modified By is SysAdmin.
Using the following code:
SPList list = newWeb.Lists[_properties.List.Title];
string destUrl = list.RootFolder.Url + "/" + newFileName + extension;
SPFile fileToMove = list.Items[_properties.ListItemUniqueId].File;
SPFolder folder = newWeb.GetFolder(list.RootFolder.Url);
byte[] bin = fileToMove.OpenBinary();
SPUser author = fileToMove.Author;
folder.Files.Add(destUrl, bin, author, author, DateTime.Now, DateTime.Now);
fileToMove.Delete();
Allow me to move the file and keep the history if i already have a version. I can now get the Modified By field filled by the real user who is uploading and not the SysAdmin BUT I'm losing the meta-data's selected during the upload.
Thank you for your support,
Fix.
Use item.Update() instead of SystemUpdate(). It should retain the identity of logged in user.
Thank you for your support.
I have solved my issue by using the following code:
folder.Files.Add(destUrl, bin, fileToMove.Properties, author, author, DateTime.Now, DateTime.Now, true);
Now, I have the Modified By value filled with the user who is uploading, the meta-data's are still there and the versioning too.

How To find Cross References(Internal Links) In Pdf File Using ItextSharp Lib

Hi I am using ItextSharp For searching Cross References(Internal Links) In pdf file. I already done with External Links.
Please Post If u have any solutions.
//Get the current page
PdfDictionary PageDictionary = R.GetPageN(page);
//Get all of the annotations for the current page
PdfArray Annots = PageDictionary.GetAsArray(PdfName.ANNOTS);
//Make sure we have something
if ((Annots == null) || (Annots.Length == 0))
// return null;
{
Console.WriteLine("nothing");
}
//Loop through each annotation
if (Annots != null)
{
foreach (PdfObject A in Annots.ArrayList)
{
//Convert the itext-specific object as a generic PDF object
PdfDictionary AnnotationDictionary = (PdfDictionary)PdfReader.GetPdfObject(A);
//Make sure this annotation has a link
if (!AnnotationDictionary.Get(PdfName.SUBTYPE).Equals(PdfName.LINK))
continue;
//Make sure this annotation has an ACTION
if (AnnotationDictionary.Get(PdfName.A) == null)
continue;
//Get the ACTION for the current annotation
PdfDictionary AnnotationAction = AnnotationDictionary.GetAsDict(PdfName.A);
// PdfDictionary AnnotationAction = (PdfDictionary)AnnotationDictionary.Get(PdfName.A);
//Test if it is a URI action (There are tons of other types of actions, some of which might mimic URI, such as JavaScript, but those need to be handled seperately)
if (AnnotationAction.Get(PdfName.S).Equals(PdfName.URI))
{
PdfString Destination = AnnotationAction.GetAsString(PdfName.URI);
string url1 = Destination.ToString();
}
}
}
You've already done most of the work. Please take a look at the following screen shot:
You see the /Annots array of a page. You are already parsing that array in your code and you skip all annotations that aren't of the /Subtype /Link or don't have an /A key, which is excellent.
Currently you're only looking for values of /S that are of type /URI. You say you're already done with external links, but that's not true: you should also lok for entries where /S is /GoToR (remote goto). If you want internal links, you need to look for /S values equal to /GoTo, /GoToE, and (in the future) /GoToDp. Maybe you also want to remove the /JavaScript actions, because they can also be used to jump to a specific page.
Please download The ABC of PDF and take a look at table 3.11 for more info. (The book is available for free.)

nlobjFile.getValue does not work in Suitelet

I have used the following code in a NetSuite Suitelet to upload and process a file:
function main(request,response){
if (request.getMethod() == 'GET'){
var form = nlapiCreateForm('Item Import Correction', false);
var fileField = form.addField('custpage_file', 'file', 'Select CSV');
form.addSubmitButton();
response.writePage(form);
}else{
try{
var file = request.getFile("custpage_file");
var content = file.getValue();//exception
response.write(content);
}catch(ex){
response.write('Exception:'+ex);
}
}
}
When I select a file and submit it, I get an exception on calling getValue() on nlobjFile. Here is the output of response:
Exception:JavaException: java.lang.NullPointerException: charsetName
However, I replace the getValue() call with some other method of the same object like getSize() or getType(), the code works fine.
I just want to parse a file selected by user in a Suitelet.
getFile() - Returns a file added through the nlobjForm.addField(name, type, label, sourceOrRadio, tab) method. When adding a file field type, you will set the type parameter of 'file'.
Make sure that the field you are referencing to using getFile() do exists in the form.
Calling the setEncoding() method on nlobjFile did the trick for me. I was using Chinese Encoding so this was the code that worked for me
var file = request.getFile("custpage_file");
file.setEncoding('GB18030');// Chinese
var content = file.getValue();//no exception

How to restore selected path in FolderBrowserDialog

In my application i just want to restore the path which was selected previously..
using (FolderBrowserDialog dlgDirestorySelector = new FolderBrowserDialog())
{
string directoryName;
dlgDirestorySelector.ShowNewFolderButton = false;
if (dlgDirestorySelector.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
directoryName = dlgDirestorySelector.SelectedPath;
}
//Processing code
}
You want to set the RootFolder property before you show the dialog.
Alternatively if the folder path is custom (and not a special folder), you simply need to set the SelectedPath property before showing the dialog (there are some rules around the path being set, explained in the "Remarks" section of the documentation I linked).

Resources