We've setup liferay to use JackRabbit as its document repository. Now what I'm trying to do is retrieve an specific document, and all I know about it is it's name, and sometimes the name of the folder it may be located in.
I know DLFileEntryLocalServiceUtil allows me to retrieve said document but requires me to have it's id before handing it over. My question is, how can I get the id of the file I'm looking for if all I have is the file name and it's location?
Below code snippet could help you,
FileEntry fileEntry = DLAppServiceUtil.getFileEntry(repositoryId, CREATED_FOLDER_ID, fileName);
In above, you have pass repositoryId could be equivalent to groupId which you can get it from themedisplay.getGroupId(), your folderId and fileName
you can get folderId by below code,
long FOLDER_ID = 0;
long repositoryId = themeDisplay.getScopeGroupId();
long parentFolderId = DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
List<Folder> lFolder = DLAppServiceUtil.getFolders(repositoryId, parentFolderId);
for (Folder folder : lFolder)
{
if (folder.getName().equalsIgnoreCase(FOLDER_NAME))
{
FOLDER_ID = folder.getFolderId();
break;
}
}
Please let me know if it helps
Related
I found a useful script long ago and installed it. Now I want to delete it so it's no longer running, but I have no idea where it is stored so I can delete it. And I don't know it's exact filename to search for it. How do I find the script?? it watches a shared folder on Google Drive and emails me when the contents of the folder are changed.
I need to find this script and delete it.... suggestions????
How about something like this? It uses Mime types to find the scripts.
function findGoogleScripts() {
var ssNew = SpreadsheetApp.create("GoogleScriptsOnMyDrive");
SpreadsheetApp.setActiveSpreadsheet(ssNew);
var sheet = ssNew.getSheets()[0];
var files = DriveApp.getFiles();
sheet.appendRow(["File Name", "Mime Type"]);
while (files.hasNext()) {
var mType, theFile;
var tempArray = [];
theFile = files.next();
mType = theFile.getMimeType();
if (mType.equals("application/vnd.google-apps.script")) {
tempArray.push(theFile.getName());
tempArray.push(mType);
sheet.appendRow(tempArray);
}
}
}
I wondered if someone could help. We use Google Apps for Education. Within the system we have a shared folder where teachers can place files for students to access. E.g. The entire team of 8 science teachers all add files to "Science Shared."
Science Shared folder is on a separate google account "science-shared#domain.com"
Over time, files will take up quota of individual users and if they leave and their account is deleted, all these files will go. We obviously do not want to transfer their entire data to science-shared using the transfer facility.
Ideally, I am looking for some sort of script which can traverse through the shared folder and change the permissions of each file and folder so that science-shared is the owner and the individual teacher has edit access.
Is this possible and if so, can anyone provide some help on how/where to start...clueless at the moment.
Thanks in advance.
Edit:
Refer to issue 2756, noting that an administrator cannot change the ownership of files via Google Apps Script:
...It's related to the fact that you can't change the own for files
you don't own. This error occurs for any illegal ACL change, such as
trying to call addEditor() when you are a viewer.
To change the ownership of files not owned by the administrator, they must use the Google Drive SDK, authenticated via OAuth.
This is certainly possible, although only for files owned by the user running the script.
Here's a script that will find all the files owned by the current user in the Science Shared folder, and transfer ownership to user science-shared. It's designed as a spreadsheet-contained script, which creates a custom menu and uses the spreadsheet Browser UI. Put the spreadsheet into your shared directory, and any teacher should be able to use it to transfer their own files, wholesale.
An admin should be able to use the script to change ANY teacher's files - just collect the id of the origOwner, and pass it to chownFilesInFolder.
Caveat: It only deals with files, not sub-directories - you could extend it if needed.
/**
* Find all files owned by current user in given folder,
* and change their ownership to newOwner.
* Note: sub-folders are untouched
*/
function chownFilesInFolder(folderId,origOwner,newOwner) {
var folder = DriveApp.getFolderById(folderId);
var contents = folder.getFiles();
while(contents.hasNext()) {
var file = contents.next();
var name = file.getName();
var owner = file.getOwner().getEmail();
// Note: domain security policies may block access to user's emails
// If so, this will return a blank string - good enough for our purposes.
if (owner == origOwner) {
// Found a file owned by current user - change ownership
Logger.log(name);
//file.setOwner(newOwner);
}
}
};
/**
* Spreadsheet browser-based UI driver for chownFilesInFolder()
*/
function changeOwnership() {
var resp = Browser.msgBox("Transfer 'Science Shared' files",
"Are you sure you want to transfer ownership of all your shared files?",
Browser.Buttons.YES_NO);
if (resp == "yes") {
var folderName = "Science Shared";
// Assume there is just one "Science Shared" folder.
var folder = DriveApp.getFoldersByName(folderName);
if (!folder.hasNext()) {
throw new Error("Folder not found ("+folderName+")");
}
else {
var folderId = folder.next().getId();
var origOwner = Session.getActiveUser().getEmail(); // Operate on own files
var newOwner = "science_shared#example.com";
chownFilesInFolder(folderId,origOwner,newOwner);
Browser.msgBox("Operation completed", Browser.Buttons.OK);
}
}
else Browser.msgBox("Operation aborted", Browser.Buttons.OK);
}
/**
* Adds a custom menu to the active spreadsheet, containing a single menu item
*/
function onOpen() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var entries = [{
name : "Transfer 'Science Shared' files",
functionName : "changeOwnership"
}];
spreadsheet.addMenu("Science-Shared", entries);
};
I hope that helps get you started.
I'm currently coding a module where users can add secure folders.
But the instance method requires a parameter of an instance name, i've no idea what they mean. Could someone explain it to me?
DotNetNuke.Services.FileSystem.SecureFolderProvider.Instance("Test2").AddFolder(txtFolderName.Text, new FolderMappingInfo
{
PortalID = base.PortalId,
MappingName = txtFolderName.Text
});
Any suggestions what i am doing wrong?
With some help of garethbh, i came up with this:
// Get folder mapping
var folderMapping = FolderMappingController.Instance.GetFolderMapping(PortalId, "Secure");
// Add folder and get the result back of the folder information
var folder = FolderManager.Instance.AddFolder(new FolderMappingInfo
{
FolderProviderType = folderMapping.FolderProviderType,
FolderMappingID = 9,
Priority = 2,
PortalID = PortalId,
}, portalFilePath);
This works fine for me.
You need to pass in the name of your folder mapping provider type. If you search for usages of SecureFolderProvider's base class (FolderProvider), you'll see what you need.
Eg:
var folderMapping = FolderMappingController.Instance.GetFolderMapping(PortalId, "Secure");
if (folderMapping != null)
{
SecureFolderProvider.Instance(folderMapping.FolderProviderType).AddFolder(folderPath, folderMapping);
}
I've never actually used the secure folder provider before so I'm just guessing you need the one with the 'Secure' mapping name (but you may want to use 'Database' depending on your needs or create your own folder provider). See the FolderMappings table in the database for available types.
From the DNN wiki http://www.dnnsoftware.com/wiki/Page/Folder-Types and http://www.dnnsoftware.com/wiki/Page/Folder-providers
I want to understand the moveFileToFolder script that is listed as an example when you select google drive scripts http://www.google.com/script/start/ (click "Start Scripting" then select "Drive" option in "Create script for" menu)
The code is below. My question is how would I alter this code so that it could be used to move the file "Austin" into the folder "Texas"? This is presuming that the file "Austin" is a google doc which is currently sitting in my main google drive file list and the folder "Texas" is also currently sitting in my main google drive list.
There are a few other posts regarding moving files in drive and I understand the main concepts but I can't seems to successfully procure the file or folder ID's. Any help greatly appreciated?
/**
* This script moves a specific file from one parent folder to another.
* For more information on interacting with files, see
* https://developers.google.com/apps-script/class_file
*/
function moveFileToFolder(fileId, targetFolderId) {
var targetFolder = DocsList.getFolderById(targetFolderId);
var file = DocsList.getFileById(fileId);
file.addToFolder(targetFolder);
};
now I had the same task and used this code:
var file = DriveApp.getFileById(fileId)
var folder = DriveApp.getFolderById(folderId);
folder.addFile(file);
Check out function getFolderByName in https://gist.github.com/suntong001/7955694 to see how to get folder ID by its name. For files the principle is the same.
function addDocToPublic() {
// Create random filename
var fn = "doc" + Math.floor(10000 * Math.random()) + ".doc";
// Create file with very MIME TYPE and return file ID
var fh = DriveApp.createFile(fn, "Das ist das " + fn + " Testfile", MimeType.MICROSOFT_WORD);
// Get first/next Iterator ID ( = folder ID) for Folder (with name PUBLIC)
var fid = DriveApp.getFoldersByName("PUBLIC").next();
// Copy File to Folder (using file and folder IDs
fh.makeCopy(fn,fid);
// Remove Source File
fh.setTrashed(true);
}
... maybe that way ...
This is a follow up question of Where is that file on my system?
Tons of questions and answers all over SO and the internet but I can't find any that gives an answer to this specific question.
All is default but I can't find the file itself,
IT'S NOT THERE.
Where/how gets |DataDirectory| defined?
Where is the file saved, does it even exist? If not, what is going on?
edit: The file isn't located at AppDomain.CurrentDomain.GetData("DataDirectory").ToString(); all (sqattered) answers tell me it should be. It must be somewhere as the debugger breaks nagging about the model unequals the table when I change the model. It's not there.
The |DataDirectory| isn't a file per se. A quote from a rather old MSDN article:
By default, the |DataDirectory| variable will be expanded as follow:
For applications placed in a directory on the user machine, this will be the app's (.exe) folder.
For apps running under ClickOnce, this will be a special data folder created by ClickOnce
For Web apps, this will be the App_Data folder
Under the hood, the value for |DataDirectory| simply comes from a property on the app domain. It is possible to change that value and override the default behavior by doing this:
AppDomain.CurrentDomain.SetData("DataDirectory", newpath)
A further quote regarding your schema inconsistencies:
One of the things to know when working with local database files is that they are treated as any other content files. For desktop projects, it means that by default, the database file will be copied to the output folder (aka bin) each time the project is built. After F5, here's what it would look like on disk
MyProject\Data.mdf
MyProject\MyApp.vb
MyProject\Bin\Debug\Data.mdf
MyProject\Bin\Debug\MyApp.exe
At design-time, MyProject\Data.mdf is used by the data tools. At run-time, the app will be using the database under the output folder. As a result of the copy, many people have the impression that the app did not save the data to the database file. In fact, this is simply because there are two copies of the data file involved. Same applies when looking at the schema/data through the database explorer. The tools are using the copy in the project, not the one in the bin folder.
The |datadirectory| algorithm is located in the System.Data.dll assembly, in the internal System.Data.Common.DbConnectionOptions class. Here it as displayed by ILSpy (note the source it's now available in the reference source repository: https://github.com/Microsoft/referencesource/blob/e458f8df6ded689323d4bd1a2a725ad32668aaec/System.Data.Entity/System/Data/EntityClient/DbConnectionOptions.cs):
internal static string ExpandDataDirectory(string keyword,
string value,
ref string datadir)
{
string text = null;
if (value != null &&
value.StartsWith("|datadirectory|", StringComparison.OrdinalIgnoreCase))
{
string text2 = datadir;
if (text2 == null)
{
// 1st step!
object data = AppDomain.CurrentDomain.GetData("DataDirectory");
text2 = (data as string);
if (data != null && text2 == null)
throw ADP.InvalidDataDirectory();
if (ADP.IsEmpty(text2))
{
// 2nd step!
text2 = AppDomain.CurrentDomain.BaseDirectory;
}
if (text2 == null)
{
text2 = "";
}
datadir = text2;
}
// 3rd step, checks and normalize
int length = "|datadirectory|".Length;
bool flag = 0 < text2.Length && text2[text2.Length - 1] == '\\';
bool flag2 = length < value.Length && value[length] == '\\';
if (!flag && !flag2)
{
text = text2 + '\\' + value.Substring(length);
}
else
{
if (flag && flag2)
{
text = text2 + value.Substring(length + 1);
}
else
{
text = text2 + value.Substring(length);
}
}
if (!ADP.GetFullPath(text).StartsWith(text2, StringComparison.Ordinal))
throw ADP.InvalidConnectionOptionValue(keyword);
}
return text;
}
So it looks in the current AppDomain data first (by default, there is no "DataDirectory" data defined I believe) and then gets to the current AppDomain base directory. The rest is mostly checks for path roots and paths normalization.
On the MSDN forum there is a similiar but simplified question about this, which says:
By default the |DataDirectory| points to your application folder (as you figured out yourself in the original question: to the App_Data).
Since is just a substitution path to your database, you can define the path yourself with the AppDomain.SetData.