DNN - MappedPath is empty when updating a folder - dotnetnuke

Everytime i update one of my folders the mapped path of my folder becomes suddenly empty and i can't find a method to resolve to change it or add a new mapped path to it.
This is my code:
// Folder information
var folderInfo = new FolderInfo();
folderInfo.PortalID = base.PortalId;
folderInfo.FolderPath = txtEditFolderName.Text;
folderInfo.FolderID = Convert.ToInt16(Request.QueryString["eventID"]);
folderInfo.DisplayPath = txtEditFolderName.Text;
folderInfo.DisplayName = txtEditFolderName.Text;
folderInfo.FolderMappingID = 9;
// Update folder
FolderManager.Instance.UpdateFolder(folderInfo);
// Move folder
FolderManager.Instance.MoveFolder(folderInfo, txtEditFolderName.Text);
// TODO: REMOVE OLD DIRECTORY
// Add new directory
Directory.CreateDirectory(folderInfo.PhysicalPath);
Thanks in advance!

I was using the mappingId from another portal, that was causing the problem.
When i used the mappingId from the right portal it worked.

Related

File path access permission

I want to access a folder other than root folders in UWP. The user will select the file with a file picker and then this file will be used for software update.
I am able to provide file selection as below. Then when I read this file, I get the error that I do not have permission to access it.
var picker = new FileOpenPicker();
picker.ViewMode = PickerViewMode.Thumbnail;
picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
picker.FileTypeFilter.Add(".bin");
file = await picker.PickSingleFileAsync();
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(file.Path);
StorageFile storageFile = await storageFolder.GetFileAsync(file.Name);
var fileStream = System.IO.File.Open(storageFile.Path, FileMode.Open);
If I manually copy the folder to the root folder and it works fine with the code below.
StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
StorageFile storageFile = await storageFolder.GetFileAsync(file.Name);
var fileStream = System.IO.File.Open(storageFile.Path, FileMode.Open);
Solution for me in two ways. The first is to copy files from the outside to the root folder, the second way is to eliminate the access permission problem.Since it is a constantly changing file, I cannot import it into the project.
Uwp has strong file access restriction, File.open is not uwp api, it can only access two location, which are Application install directory and Application data locations, so your code works well when you copy this file to Application data location. Therefore, I suggest you could use StorageFile.OpenAsync method instead of File.open() to get the stream.

Drupal upload then move doesn't update path or filename in file list

I have a custom form using a "managed_file" which uploads to temp folder. Programmatically, I then load that file and move it to its permanent storage (overwriting any existing file with the* name) e.g.
// Upload file
$upfile = $this->entityTypeManager->getStorage('file')->load($fid);
// Source and destination
$sourceUri = $this->fileSystem->realpath($upfile->getFileUri());
$destinationUri = $this->fileSystem->realpath(\Drupal::config('system.file')->get('default_scheme') . "://") . '/x/y/z/XYZ_NEW.pdf';
// Move and overwrite
$this->fileSystem->move($sourceUri, $destinationUri, FileSystemInterface::EXISTS_REPLACE);
All of this works (i.e. the file physically is moved into the correct place with correct name); however, the file displayed in the listings (i.e. /admin/content/files) still shows the incorrect temporary folder as the URI.
Basically the file in the listings page seems to be showing the original filepath and name* of a previously successfully moved* file.
If I load this file with incorrect URI, i.e. using the incorrect temp path, the data loads, but then will not have a file info (as it doesn't exist. Also clicking the filename by browser under listings will show page not found and the URL showing the old URL i.e. /system/temporary?file=XYZ.pdf).
If I load this file by correct URI, i.e. using the correct destination path, file not found - same if I go to the path directly in the browser.
It appears the managed file doesn't know it was moved. How to resolve this bug?
The docs for FileSystem::move say "Moves a file to a new location without database changes or hook invocation."
So you are going to need to update the file entity with the new values..
Try this, untested:
// Upload file
$upfile = $this->entityTypeManager->getStorage('file')->load($fid);
// Source and destination
$sourceUri = $this->fileSystem->realpath($upfile->getFileUri());
$destinationUri = $this->fileSystem->realpath(\Drupal::config('system.file')->get('default_scheme') . "://") . '/x/y/z/XYZ_NEW.pdf';
// Move and overwrite
$newFileName = $this->fileSystem->move($sourceUri, $destinationUri, FileSystemInterface::EXISTS_REPLACE);
// Set the new file path on the file entity.
$upfile->setFileUri($newFileName);
// Set the file to permanent if needed.
$upfile->setPermanent();
// Save entity with changes.
$upfile->save();
I did not test this though.
You can check the functions on the file entity in the docs here
It turns out the class based methods do not update the database
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21File%21FileSystem.php/function/FileSystem%3A%3Amove/8.9.x
The procedural version does
https://api.drupal.org/api/drupal/core%21modules%21file%21file.module/function/file_move/8.9.x

How to move a shortcut in google drive

I need to move a shortcut file from one destination to another using google apps script.
Usually I would move a file or folder like this:
function move(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sStamdata = ss.getSheetByName("New");
var folderOld = DriveApp.getFolderById(folderOldId);
var destination = DriveApp.getFolderById(folderId);
var id = sStamdata.getRange('D77').getValue();
var file = DriveApp.getFileById(id);
folderOld.removeFile(file)
destination.addFile(file)
But this doesn't work with shortcuts. Any ideas?
How about this answer?
Modification points:
It seems that in the current stage, the shortcut cannot be moved using Drive service. I think that this might be resolve in the future update.
So as the current workaround, in this answer, I would like to propose to use the method of "Files: patch" Drive API v2, because Drive API of Advanced Google services is used.
When your script is modified, please modify as follows.
Modified script:
Before you run the script, please enable Drive API at Advanced Google services.
function move(){
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sStamdata = ss.getSheetByName("New");
// var folderOld = DriveApp.getFolderById(folderOldId);
// var destination = DriveApp.getFolderById(folderId);
var id = sStamdata.getRange('D77').getValue();
// var file = DriveApp.getFileById(id);
Drive.Files.patch({parents: [{id: folderId}]}, id); // Added
}
folderId is the destination folder ID.
Please confirm the file ID of the shortcut again.
Note:
For example, when the file ID of the shortcut is confirmed with the shared link using the browser, the file ID is ID of the original file. Please be careful this.
References:
Advanced Google services
Files: patch

How can I intercept the file:// requests to provide a directory listing?

I'm trying to replace the directory lists generated by Firefox by a custom one.
So, I need three things:
I need to know when Firefox tries to load a file:// URI.
I have to test if that URI targets a directory or a file.
If the target of the URI is a directory, i have to prevent Firefox from generating the directory listing, and show my own directory listing instead.
It's the first point that is the most problematic:
I read the documentation of the nsIObserverService but it doesn't do what I want (there is a http-on-modify-request but no file-on-modify-request)
I tried to use the Jetpack's addon-kit/page-mod on file://* URIs, but it seems it doesn't allow me to verify if the URI targets a directory before loading my stuff.
I read the documentation of the nsIFileProtocolHandler, but it doesn't help me.
So how can I intercept the file://* requests?
Does somebody have an idea?
I tried to use the Jetpack's addon-kit/page-mod on file://* URIs, but it seems it doesn't allow me to verify if the URI targets a directory before loading my stuff.
That's right. However, you can do the same thing that page-mod module is doing, namely listen to the document-element-inserted observer notification. Something along these lines:
var events = require("sdk/system/events");
var urls = require("sdk/url");
events.on("document-element-inserted", function(event)
{
var window = event.subject.defaultView;
if (!window) // XBL document?
return;
var url = urls.URL(window.document.URL);
if (url.scheme == "file")
{
// A file:/// URL was loaded, do something with this window
}
});
For reference: system/events module, url module.
I have to test if that URI targets a directory or a file.
The url module also allows you to get the file path, and then you can use the io/file module to access it:
var files = require("sdk/io/file");
var path = urls.toFileName(url);
var isDir = files.exists(path) && !files.isFile(path);
If the target of the URI is a directory, i have to prevent Firefox from generating the directory listing, and show my own directory listing instead.
That's the hard part. I don't think that you can prevent Firefox from generating the directory listing but calling window.stop() should have the same effect. You can then dynamically add your own contents to the window. You can use files.list(path) method to get a list of directory entries:
window.stop();
var entries = files.list(path);
for (var i = 0; i < entries.length; i++)
addEntry(window, path, entries[i]);

Using Google Picker to upload files to Google Drive and place in specific folder

I am attempting to use Google Picker to upload files to a specific folder in Google Drive. Everything works fine when I am just uploading to the root folder, but even after specifying the parent folder as shown in my code below, the files still go to the root folder, not the folder I am specifying. I am certain the folderID is correct, as I am using the same ID elsewhere to create textiles in my GAE app, and place them in subfolders. My code is below:
function createPicker() {
// Create a view to search images.
var view = new google.picker.View(google.picker.ViewId.DOCS);
view.setMimeTypes('image/png,image/jpeg');
// Use DocsUploadView to upload documents to Google Drive.
var uploadView = new google.picker.DocsUploadView().setParent('THE Parent folder ID');
var picker = new google.picker.PickerBuilder().
addView(view).
addView(uploadView).
setAppId("pressomatic").
setCallback(pickerCallback).
build();
picker.setVisible(true);
}
You have to add:
enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
In your case it becomes:
var picker = new google.picker.PickerBuilder().
enableFeature(google.picker.Feature.MULTISELECT_ENABLED).
addView(view).
addView(uploadView).
setAppId("pressomatic").
setCallback(pickerCallback).
build();
picker.setVisible(true);
}
This is a bug documented in the Picker API Forum: https://groups.google.com/forum/#!topic/Google-Picker-API/xaHcET7JYLw
You have to add:
.enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
In your case it becomes:
var picker = new google.picker.PickerBuilder()
.enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
.addView(view)
.addView(uploadView)
.setAppId("pressomatic")
.setCallback(pickerCallback)
.build();
Hope this helps.

Resources