DriveApp.getFolderById :No item with the given ID could be found, or you do not have permission to access it - google-app-maker

sorry. stuck again. I have a driveapp fileid and folderid. all correct i am sure about that. trying to just move fileid into the folderid (server-side script):
function moveFiles(sourceFileId, targetFolderId, role) {
var file = DriveApp.getFileById(sourceFileId);
file.getParents().next().removeFile(file);
DriveApp.getFolderById(targetFolderId).addFile(file);
return "1";
}
The line that crashes is the DriveApp.getFolderById() line, with the error message above (No item with the given ID could be found, or you do not have permission to access it)
these are files and folders that i own with my account. i cant see that it would be a permissions issue

My mistake...
I was using the getUrl() not the getId()... My bad

Related

POST method to upload file to Azure storage - what to return

I am creating an app where
user can upload the text file and then
find most used word and change that word in text and
show the changed text to the user.
if it is possible, I would like to
get the file’s text content before uploading when Post method is being called and save that content
so I add the “DownloadTextAsync()” method inside of the POST method, but it seems like I am calling this method to the wrong subject?
[HttpPost("UploadText")]
public async Task<IActionResult> Post(List<IFormFile> files)
{
string connectionString = Environment.GetEnvironmentVariable("mykeystringhere");
// Create a BlobServiceClient object which will be used to create a container client
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
//Create a unique name for the container
string containerName = "textdata" + Guid.NewGuid().ToString();
// Create the container and return a container client object
BlobContainerClient containerClient = await blobServiceClient.CreateBlobContainerAsync(containerName);
// Create a local file in the ./data/ directory for uploading and downloading
string localPath = "./data/";
string fileName = "textfiledata" + Guid.NewGuid().ToString() + ".txt";
string localFilePath = Path.Combine(localPath, fileName);
// Get a reference to a blob
BlobClient blobClient = containerClient.GetBlobClient(fileName);
// Open the file and upload its data
using FileStream uploadFileStream = System.IO.File.OpenRead(localFilePath);
await blobClient.UploadAsync(uploadFileStream, true);
uploadFileStream.Close();
string downloadFilePath = localFilePath.Replace(".txt", "DOWNLOAD.txt");
// Get the blob file as text
string contents = blobClient.DownloadTextAsync().Result;
//return the string
return contents;
//if (uploadSuccess)
// return View("UploadSuccess");
//else
// return View("UploadError");
}
The issues I am having are
I understood that ‘blobClient’ is the reference to the blob, where I can get the file’s data but this must be wrong?
Also it seems like I cannot use “CloudBlobContainer” nor the “CloudBlockBlob blob”. Is it because inside of the POST method, the blob has been just initialized and does not exist when these twos are executed?
Also when I test the POST method, the console throws “Refused to load the font '' because it violates the following Content Security Policy directive: "default-src 'none'". Note that 'font-src' was not explicitly set, so 'default-src' is used as a fallback.” which I googled but have no idea what it means?
I have tried different ways but keep getting CANNOT POST/“ But could not really find the solid anwers. Could this be related to my POST method?
I understood that ‘blobClient’ is the reference to the blob, where I
can get the file’s data but this must be wrong?
That's correct in a sense that you can use blobClient to perform operations on blob like upload/download etc. I am not sure why you say but this must be wrong.
Also it seems like I cannot use “CloudBlobContainer” nor the
“CloudBlockBlob blob”. Is it because inside of the POST method, the
blob has been just initialized and does not exist when these twos are
executed?
No, this is happening because you're using a newer version of SDK (version 12.x.x) and CloudBlobContainer and CloudBlockBlob are available in the older version of the SDK.
Also when I test the POST method, the console throws “Refused to load
the font '' because it violates the following Content Security Policy
directive: "default-src 'none'". Note that 'font-src' was not
explicitly set, so 'default-src' is used as a fallback.” which I
googled but have no idea what it means? I have tried different ways
but keep getting CANNOT POST/“ But could not really find the solid
anwers. Could this be related to my POST method?
Not sure why this is happening. You may want to ask a separate question for this and when you do, please include the HTML portion of your code as well.

Edit xml File and save it from c#

I have an xml file which contain images url . i am verifying the url whether url is responsive or not. If url is not responsive then i am removing that url from xml. and saving all changes . but i am getting error like
'The process cannot access the file 'E:\1.xml' because it is being used by another process'
xmlTR = new XmlTextReader(#"E:\1.xml");
PrimaryXmlDoc.Load(xmlTR);
foreach (XmlNode node in PrimaryXmlDoc.SelectNodes("/fp-hotel/Images/Url"))
{
if (CheckUrlExists(node.InnerText))
{
}
else
{
XmlElement _xmlElement = PrimaryXmlDoc.DocumentElement;
node.ParentNode.RemoveChild(node);
}
}
PrimaryXmlDoc.Save(#"E:\1.xml");
I assume that you have to Close XmlTextReader before using it second time. If you don't do that, the previous instance will keep your file open and you won't be able to open it again.
EDIT: And that's what happens here is probably that you want to save file before closing it.
Add line:
xmlTR.Close();
before
PrimaryXmlDoc.Save(#"E:\1.xml");

providing feedback for file uploads

When uploading files to a server what information should be provided to the user for feedback? I have created a website that allows users to upload files to a server. I would think a progress bar would be nice or at the very least a message to let the users know that the process was successful or not. Another issue is how do I know that the operation was successful? Right now the only thing I can think of is to check if the files exist after they are saved. I am using C# .NET 2.0 on the server side. Here is an example of the code I have for saving the files...
private void fileUpload(HttpContext context)
{
string stgDir = #"myDir",
fullPath;
HttpFileCollection hfc = context.Request.Files;
for(int i = 0; i < hfc.Count; i++)
{
fullPath = Path.Combine(BASE_PATH, stgDir);
if(!Directory.Exists(fullPath))
{
Directory.CreateDirectory(fullPath);
}
if(hfc[i].ContentLength > 0)
{
fullPath = Path.Combine(fullPath,hfc[i].FileName);
hfc[i].SaveAs(fullPath);
}
}
}
If you don't get an exception is very unlikely that there was an error saving the file, so, add a try catch and show your user an error if exception is catch, or just a friendly message indicating the file was uploaded.
Regarding the info as feedback, that's up to you and what you would like the user to know, maybe success message and a link to the file would be enough.

virtual path change

I want to change Virtual Path(The path is out of project means local system or Server.) of the file Which is save on the folder in asp.net.
Code is
DataTable dtFiles =
GetFilesInDirectory(HttpContext.Current.Server.MapPath(UPLOADFOLDER));
gv.DataSource = dtFiles;
gv.DataBind();
if (dtFiles != null && dtFiles.Rows.Count > 0)
{
double totalSize = Convert.ToDouble(dtFiles.Compute("SUM(Size)", ""));
if (totalSize > 0) lblTotalSize.Text = CalculateFileSize(totalSize);
}
private static string UPLOADFOLDER = "D:/Uploads";
And the error show "D:/Uploads is not a valid virtual path.".
If you want to get the files in a directory and you know the full path, then you don't need to use Server.MapPath(). Just use the path.
Incidentally, the path delimiter is incorrect in your code. The string "D:/Uploads" should be #"D:\Uploads" (note the leading # sign to denote a string that should be treated literally and not escaped).
Of course. You're telling your server to map path that is completely off the IIS. How is it supposed to do? If you're using a web application, try to avoid such ideas completely. Even though it is possible, it isn't a good idea because of security issues you can run into.

Drupal user access callback selective response

Please bear with this Drupal API novice whilst I explain some background stuff!
I have been experimenting with the code below to create 2 separate responses when my users click on a custom node creation link. By default, a page opens that allows users to go through the usual steps in creating a node.
What my module does is check if the user has specific permissions and either allow them to proceed in creating the node or throw up an access denied page.
function mymodule_menu_alter(&$items) {
$items["node/add/page/%"]['access callback'] = 'mymodule_access_callback';
}
function mymodule_access_callback(){
if( user_access('open sesame') ){
drupal_set_message("successfully intecepting new node creation");
return true;
}
return false;
}
The node/add/page is blocked successfully but it does so in both cases. The if statement determines if the user has a certain permission and within it I added return true which resulted in the following error:
Fatal error: require_once() [function.require]: Failed opening
required '/node.pages.inc' (include_path='.:') in
/var/www/vhosts/mysite.co.uk/httpdocs/includes/menu.inc on line 347
As a novice, I am not sure what I need to do in order to avoid the access denied page for the right users.
Try this:
function mymodule_menu_alter(&$items) {
$items["node/add/page/%"]['access callback'] = 'mymodule_access_callback';
$items["node/add/page/%"]['file'] = drupal_get_path('module', 'node') . '/node.pages.inc';
}
EDIT
Try changing the second line above to this:
$items["node/add/page"]['file'] = drupal_get_path('module', 'node') . '/node.pages.inc';
It's an attempt to explicitly set the file path for the parent item of the path you're defining.
Also this might be a stupid thing to say but every time you make a change to hook_menu_alter() make sure you clear Drupal's caches so the changes are picked up.

Resources