Can't import a file into a page using the import toolkit - kentico

I'm working through an import using the Kentico Import Toolkit for Kentico 12.
My intention is to import content from a CSV file into pages in Kentico. It's fundamentally working, however, I can't get it to take a PDF on the file system and bring that in as a binary object into a Kentico page property.
In my CSV file I have a column called "FileName", and in Kentico I have a page type called "Asset" which has a property called "File" which is of type File.
In my column mapping I have the "File" property mapped as follows:
#<file>c:\temp\filesfortesting\{%FileName%}
The import runs and the pages are created however no files are actually imported and mapped to the File property on the page.
Any suggestions as to how I can fix this? Do I have the mapping right?

I guess you want to import is as a page attachment. In this case, you need to import the pages first and then, in a second run import the page attachments.It might be easier to create a simple tool and use API to do the migration.
At first I will clarify the types of attachments in Kentico:
Unsorted attachments: these are the attachments added through e.g.
WYSIWYG editor and are available on page's Properties -> Attachments
tab
Grouped attachments: these are the files attached to pages using the
Attachments form control. You can change the order of the attachments
and you manage them on the Form tab
CMS.File and direct file field attachments: these are the files
uploaded to a page on the Form tab using the Direct uploader form
control.
So, in the import toolkit, you will select the page attachments to be imported and then configure the source and import the attachments into the CMS_Attachment table.
The import toolkit supports importing of the unsorted attachments only. So, if you want to move the attachments you may need to do it in multiple runs + execute some API code.
When importing the attachments, you need to set the WHERE condition to match your pages, in my case I was using /news/% path:
Where condition:
AttachmentDocumentID IN (SELECT DocumentID FROM CMS_Document WHERE DocumentNamePath LIKE '/news/%')
Then, select some dummy page where to import all the attachments. remember? KIT imports attachments as unsorted. In this case I used the parent /news page with DocumentID = 1063 so all attachments are assigned to this page.
Then, execute code similar to this to move the attachments to respective pages:
// Creates a new instance of the Tree provider
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
// Gets the parent page
TreeNode page = tree.SelectNodes()
.Path("/news")
.OnCurrentSite()
.Culture("en-us")
.TopN(1)
.FirstOrDefault();
if (page != null)
{
foreach (DocumentAttachment attachment in page.AllAttachments)
{
// Perform any action with the attachment object (DocumentAttachment), NewsTeaser is the target page’s direct file upload field where I want to get the attachment
TreeNode targetPage = tree.SelectNodes()
.Type("CMS.News")
.Where("NewsTeaser = '" + attachment.AttachmentGUID + "'")
.TopN(1)
.Culture("en-us")
.OnCurrentSite()
.FirstOrDefault();
if (targetPage != null)
{
// Edits the attachment's metadata (name, title and description) and set the right AttachmentDocumentID and AttachmentIsUnsorted to false
attachment.AttachmentDocumentID = targetPage.DocumentID;
attachment.AttachmentIsUnsorted = false;
// Ensures that the attachment can be updated without supplying its binary data
attachment.AllowPartialUpdate = true;
// Saves the modified attachment into the database
attachment.Update();
}
}
}

Related

Form Thumbnail URL for SharePoint large video Files

I am trying to form SharePoint file's thumbnail URL (in Office 365) as mentioned in https://www.techmikael.com/2020/01/retrieving-thumbnailspreviews-for.html. This uses SharPoint site ID, List ID and file item's Unique ID to generate thumbnail URL.
/_api/v2.0/sites/${this.context.pageContext.site.id}/lists/${listId}/items/${itemUniqueId}/driveItem/thumbnails/0/${maxHeight}/content${noRedirect}
But I always get error message 404 Not Found. I used search API to verify that the thumbnail URL exists in "PictureThumbnailURL" field.
I also tried with _api/v2.1/... but get the same error. Just to be sure I ran the sample SPFx web part solution available here: https://github.com/pnp/sp-dev-fx-webparts/tree/main/samples/js-msgraph-thumbnail and get the same 404 Not Found error for images.
I have already been using getpreview.ashx but I don't see preview for large video files but get the preview URL in the search even for those large files.
I can't use search API since search result may not be immediately available to get and save the thumbnail URL.
Is there any other way to get the picture thumbnail URL using REST API in SPFx?
I found a way to generate the thumbnail URL using drive API. There are properties on File object VroomDriveID and VroomItemID. Using these properties we can format the link as below:
https://{tenantname}.sharepoint.com/_api/v2.1/drives/${VroomDriveID}/items/${VroomItemID}/thumbnails/0/c400x99999/content?preferNoRedirect=true
Below is sample code to get these properties from SharePoint:
let thumbnailURL = "";
let uniqueID = "{file's unique id}";
let resolution = "c400x99999";
let caml: ICamlQuery = {
ViewXml:
<View><Query><Where><Eq><FieldRef Name='UniqueId' /><Value Type='Text'>${uniqueID}</Value></Eq></Where></Query></View>
};
// get list items
const fileItems: IItems = await sp.web.lists.getByTitle("DocLibTitle").getItemsByCAMLQuery(caml, 'FieldValuesAsText, File/VroomDriveID,File/VroomItemID');
console.log("Items: ", fileItems);
let VroomDriveID = fileItems[0]["File"]["VroomDriveID"];
let VroomItemID = fileItems[0]["File"]["VroomItemID"];
thumbnailURL = "https://{tenantname}.sharepoint.com/_api/v2.1/drives/${VroomDriveID}/items/${VroomItemID}/thumbnails/0/${resolution}/content?preferNoRedirect=true";
console.log(thumbnailURL);
I hope this helps!

Display Notification for particular Shared Document Folder in Sharepoint

I am trying to modify my SharePoint 2010 site so that when a user navigates to a specific folder within the default "Shared Documents" document library a notification to the user displays describing the folder/file naming convention for that particular folder. I tried adding a content editor to the page but this shows for all folders within the "Shared Documents" library. Is there a way to show this notification for a particular folder or hide it for folders not equal to the desired folder?
Update: I tried saving the following script to a text file, uploading it to my sharepoint site, and then pasting the url to the text file in the CEWP with no result.
<script language="javascript" type="text/javascript">
var url = window.location.href;
var rootFolderUrl = getQueryStringParamvalue("RootFolder");
var folderRelativeUrl = '%2Fsites%2FBusiness%5FArchitecture%2Fbusinesstransformation%2FShared%20Documents%2FTransformation%20Projects';
if(rootFolderUrl == folderRelativeUrl) {
alert("Note: Please utilize the MMM-YYYY standard naming convention when adding folders and files.")
}
</script>
Presuming you have added javascript under content editor webpart to display the notification, you just need to check the RootFolder query string parameter of the url of the current page.
SharePoint appends the relative url of the folder under the RootFolder query string parameter of the current page. Your script should read the current url and compare with the relative url of the folder for which you need to show the notification.
The pseudo code would look something like below:-
var url = window.location.href;
var rootFolderUrl = getQueryStringParamvalue("RootFolder");
var folderRelativeUrl = <relative url of the folder for which you want to show the notification>;
if(rootFolderUrl == folderRelativeUrl) {
<code to show the notification here.>
}

Typo3 FAL show file browser popup in backend module

I have a site which shows a teaser (image+text) on all pages.
This should be editable from admin, so I created a small backend module (a simple form) where the admin should set the image and the text and save them in Typo3's registry db table:
This is how I save the text:
$request = $this->controllerContext->getRequest();
$arguments = $request->getArguments();
$registry = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance( 't3lib_Registry' );
$extKey = $request->getControllerExtensionKey();
$registry->set( $extKey, 'text', $arguments['settings']['text'] );
but I don't know how to add an "Add image" link to display the file browser and get the url/id of the selected file.
Any ideas?
Thanks.
In order to have a file picker you will need to have a TCA for a FAL field. A TCA is usually connected to a table and I wouldn't know of any implementation with the registry as a "storage backend".
This means you would have to create TCEForms yourself and then intercept the saving process. This is possible but rarely used and rather complicated, see an example here:
https://git.typo3.org/Packages/TYPO3.CMS.git/blob/TYPO3_4-5:/typo3/sysext/version/ws/workspaceforms.php
(for TYPO3 4.x, for 6.x the class names have to be adjusted)
So I would suggest that you extend the table pages with a field for text and a FAL field instead of trying to write an own backend module for this purpose.

Building a list of downloadable items in Orchard 1.6

I'm fairly new to Orchard and I'm wondering about the "best" way of building a basic list of documents with a download link?
Say the scenario is this, I want to make a list of newsletters, the news letter are in PDF format and the users should be able to download then straight from the list view.
An admin, should easily be able to add a new newsletter and it should turn up in the list.
My current train of thought is to, all through the dashboard,
create a content type "Newsletter" with a title field and a Media picker field, using the media picker field to upload the PDF file.
Then create a query, with the filter on Content type "Newsletter"
Create a projection pointing to the query
However, this only gives me a list of content items, showing their title as links back to the actual content item.
I've tried adding a layout to the query and set it to display properties instead of content. By doing that I can get a list where I can control the "output" a bit more. And I've gotten it to list the title and by doing a Rewrite and putting in the MediaPicker.Url, it also displays the URL in the list. This is all good but here I get stuck..
As the MediaPicker.URL outputs the url in the format like ~/media/default/xyz/filename.pdf, I cant just put it into a a href, it doesn't give a correct download link to the file.
Soo, question is, am I thinking and doing this totally the wrong way or am I missing something obvious? All ideas and suggestions and more then welcome.
Use or adapt the following template override in your theme:
#{
var url = Model.ContentField.Url;
}
#if(Model.ContentField.Url != null) {
if (url.StartsWith("~/")) {
url = Href(url);
}
<div class="media-picker-field attachment-pdf">
<span>download</span>
</div>
}
Modify the text as needed. This template was a Fields.MediaPicker-PDF.cshtml that was used for a media picker field named PDF.

JSF 1.2 response capture including resources

I am using JSF 1.2 with RichFaces. Is it possible to mimic the "Save as" of a web browser client? To be more precise, I want to add a "Download zip" on a page. The purpose is to generate a zip archive containing the HTML generated page with all necessary files to open that page with a correct layout.
I succeeded in the past to capture the HTML page by means of a HttpResponseWrapper.
But as soon as the page contains RichFaces components, some JS and images are required for a correct display. How could I get those resources to add them in the zip?
Use a HTML parser like Jsoup. It can easily find CSS/JS/image elements by jQuery-like CSS selectors and give you the resource URLs back so that you can download them individually.
InputStream input = new URL(url).openStream();
// ... Save webpage itself.
Document document = Jsoup.parse(savedWebPage, "UTF-8", url);
for (Element stylesheet : document.select("link[rel=stylesheet]")) {
InputStream input = new URL(stylesheet.absUrl("href")).openStream();
// ... Save individual stylesheet file.
}
for (Element script : document.select("script[src]")) {
InputStream input = new URL(script.absUrl("src")).openStream();
// ... Save individual script file.
}
for (Element img : document.select("img[src]")) {
InputStream input = new URL(img.absUrl("src")).openStream();
// ... Save individual image file.
}
CSS background images are not taken into account. You could consider a CSS parser like SAC on every individual CSS file.

Resources