JSX/Photoshop: activeDocument.path + string doesn't work - photoshop

when I execute this piece of JSX from Photoshop works like a charm:
var myPath = app.activeDocument.path;
alert (myPath);
var files = myPath.getFiles();
alert(files.length);
But this one gives to me an error:
var myPath = app.activeDocument.path+"/folder/";
alert (myPath);
var files = myPath.getFiles();
alert(files.length);
Error 24: myPath.getFiles is not a function...
Any clue on what I'm doing wrong?
Thanks

You need to use this:
var myPath = new Folder(app.activeDocument.path + "/folder");

Related

Get complete host name

I want to know the full name of a remote page making an http call to my server. I am working with VB.NET and the page that is called is .ashx. At the moment I use this code snippet but I can only intercept the domain name but I don't know the exact page making the call. I've tried everything. Can you help me?
Dim _res As String = "" _hostaddress = context.Request.UserHostAddress Dim _header As NameValueCollection = context.Request.Headers _res = _header.GetValues("User-Agent").First()
Dim _res As String = "" _hostaddress = context.Request.UserHostAddress Dim _header As NameValueCollection = context.Request.Headers _res = _header.GetValues("User-Agent").First()

Upload a file to SharePoint using REST API and vb.net

I have a project to upload files to Sharepoint using REST API ( POST).
I am using vb.net and RestSharp. Code is below. this code is working.
I am able to do with the small Text file only and the file is getting properly upload into Sharepoint. But when it comes to another file format ( XLS, XLSX, PDF, JOG, Doc ..etc) with a file size greater than 1 MB file is getting uploaded with it, not in a readable format. I tried to upload a ZIP file for 55 MB it is getting Uploaded. But When I download the same uploaded file I am not able to read it.
Can anyone please help me, to get this fixed?
** I would need a solution to upload any file format for any size ( In my project I will not use any file more than 500 MB for upload. )
Below is the code is tried.
Public Sub UploadFile2()
Dim FullfileName As String = "E:\Desktop\try\FileToUpload.xlsx"
Dim NewFileName As String = "NewFile.xlsx"
Dim uploadFileUrl As String = SiteUrl + "_api/web/lists/getByTitle('Documents')/RootFolder/Files/Add(url='" + NewFileName + "', overwrite=true)"
Dim client = New RestClient(uploadFileUrl) With {
.Timeout = -1
}
Dim UploadRequest = New RestRequest(Method.POST)
UploadRequest.AddHeader("Accept", "application/json;odata=verbose")
UploadRequest.AddHeader("X-RequestDigest", DigestValue)
UploadRequest.AddHeader("Authorization", "Bearer " + AccessToken)
UploadRequest.AddHeader("Content-Type", "multipart/form-data")
UploadRequest.AlwaysMultipartFormData = True
UploadRequest.AddFile("FileName", FullfileName)
UploadResponse = client.Execute(UploadRequest)
End Sub
Looks like you need to pass the Content-Length header.
For anyone interested, this worked for me:
Public Sub UploadFile2()
Dim FullfileName As String = "E:\Desktop\try\FileToUpload.xlsx"
Dim NewFileName As String = "NewFile.xlsx"
Dim uploadFileUrl As String = SiteUrl + "_api/web/lists/getByTitle('Documents')/RootFolder/Files/Add(url='" + NewFileName + "', overwrite=true)"
Dim client = New RestClient(uploadFileUrl) With {
.Timeout = -1
}
Dim UploadRequest = New RestRequest(Method.POST)
UploadRequest.AddHeader("Accept", "application/json;odata=verbose")
UploadRequest.AddHeader("X-RequestDigest", DigestValue)
UploadRequest.AddHeader("Authorization", "Bearer " + AccessToken)
UploadRequest.AddHeader("Content-Type", "application/octet-stream")
UploadRequest.AddParameter("application/octet-stream", File.ReadAllBytes(FullfileName), ParameterType.RequestBody)
UploadResponse = client.Execute(UploadRequest)
End Sub

mystery metacafe thumb issue

I'm having issue to retrive thumb from metacafe video id.
The problem is that even the url seems to be correct (after opening source html) but when we change the new ID in the same URL it will return 400 error page.
Here is the working url:
http://cdn.mcstatic.com/contents/videos_screenshots/11827000/11827430/preview.jpg
Here is not working url:
http://cdn.mcstatic.com/contents/videos_screenshots/11826998/11826998/preview.jpg
Seems like really crazy that even the wrong URL contains same direct thumb link but when type it will get 404 not found.
I hope someone could solve this mystery.
Public Sub getThumb()
Dim thumbURL As String = "http://cdn.mcstatic.com/contents/videos_screenshots/"
Dim videoID As String = "1827000"
PreviewBox.ImageLocation = (thumbURL + videoID + "/" + videoID + "/preview.jpg")
End Sub
After some external help from someone I get this done.
I hope it will help someone.
Public Sub getThumb()
Dim thumbURL As String = "http://cdn.mcstatic.com/contents/videos_screenshots/"
Dim videoID As String = "1827000"
PreviewBox.ImageLocation = (thumbURL + videoID.Remove(videoID.Length - 3) + "000/" + videoID + "/preview.jpg")
End Sub

Cefsharp: Get hyperlinks from document

I am used to getting hyperlinks in a document like this:
Dim html As String =
"var linksArray = new Array(); " &
"for (var i = 0; i < document.links.length; i++) {" &
"linksArray[i] = [String(document.links[i].innerHTML), String(document.links[i].innerText), String(document.links[i].href)];" &
"} " &
"return linksArray;"
Try
Dim linksArray As JSArray = _Browser.WebView.EvalScript(String.Format("(function(){{ {0} }})()", html))
For Each obj As Object In linksArray
Dim sInnerHTML As String = obj(0).ToString().Trim()
Dim sInnerText As String = obj(1).ToString().Trim()
Dim sHRef As String = obj(2).ToString().Trim()
Dim nItem As New clsURL
nItem.HRef = sHRef
nItem.InnerHTML = sInnerHTML
nItem.InnerText = sInnerText
nList.Add(nItem)
Next
However, CefSharp does not have JSArray.
Can anybody tell me what would be the way to do that with CefSharp?
Thank you!
Have a read over the FAQ, particularly https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions#2-how-do-you-call-a-javascript-method-that-return-a-result
EvaluateScriptAsync will return a List<object> (in yours case each entry will likely be another List<object as you've got nested arrays)
I've created a Gist as an example, it's in C#, you should be able to port it to VB.Net (I cannot help you there)
https://gist.github.com/amaitland/9d354376960b0cd9305a
(I plan to add a slightly more detailed example to the FAQ, so yours case seems like a reasonable candidate).
As a side note, when executing blocks of code using EvaluateScriptAsync I recommend using an anonymous closure.

openoffice calc macro for CSV saving

Given: I recorded a simple macro in Openoffice to save my worksheet as a CSV file. Here it is.
sub toCSV
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = "file:///path/csv/filename.csv"
args1(1).Name = "FilterName"
args1(1).Value = "Text - txt - csv (StarCalc)"
args1(2).Name = "FilterOptions"
args1(2).Value = "59,34,76,1"
dispatcher.executeDispatch(document, ".uno:SaveAs", "", 0, args1())
end sub
Problem: I want to add some features to this function. 1. I need to get the current XLS filename so that I can put that at the end of my static path. So file:///path/csv/ is going to always remain the same, and filename.csv will be coming from filename.xls. 2. Well, I'll need to do some regex replacement on that filename-revision01.xls to ultimately get filename.csv.
I can do regex matching well, I'm simply looking for hints on string concatenation, how to get the current filename, and how to write a regex expression within a macro.
BTW, what is this language called!?
This is the solution I came up with to help in exporting a CSV (with my export options, filename adjustment, and file location) with one click.
I'm on a Mac, so the file paths will be for such an operating system. The information that helped me do this is here.
REM ***** BASIC *****
sub toCSV
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
FileURL = ThisComponent.URL
oMasterScriptProviderFactory = createUnoService("com.sun.star.script.provider.MasterScriptProviderFactory")
oMasterScriptProvider = oMasterScriptProviderFactory.createScriptProvider("")
oScriptReplace = oMasterScriptProvider.getScript("vnd.sun.star.script:Tools.Regex.js?language=JavaScript&location=user")
sReturn = RegExpReplace(oScriptReplace, FileURL, "(.*)/(\w*-\w*)(-revision\d*)+\.xls", "i", "$2.csv")
dim args1(2) as new com.sun.star.beans.PropertyValue
args1(0).Name = "URL"
args1(0).Value = "file:///Users/joe/Documents/mydocuments/trunk/my%20projects/dictionary/verbsXLS/proofed/csv/" + sReturn
args1(1).Name = "FilterName"
args1(1).Value = "Text - txt - csv (StarCalc)"
args1(2).Name = "FilterOptions"
args1(2).Value = "59,34,76,1"
dispatcher.executeDispatch(document, ".uno:SaveAs", "", 0, args1())
end sub
function RegExpReplace(oScriptReplace as Object, sSource as String, sRegExp as String, sGlobUpcase as String, sReplace as String) as String
RegExpReplace = oScriptReplace.invoke(Array(sSource, sRegExp, sGlobUpcase, sReplace ), Array(), Array())
end function
Here is a bit of javascript that the above macro relies upon. This file is named ~/Library/Application\ Support/OpenOffice.org/3/user/Scripts/javascript/Tools/Regex.js and is hardcoded and referenced above.
sSource = String(ARGUMENTS[0])
sRegExp = String(ARGUMENTS[1])
sGlobUpcase = (ARGUMENTS[2])
sReplace = String(ARGUMENTS[3])
myRe = new RegExp(sRegExp, sGlobUpcase)
ret = sSource.replace(myRe, sReplace)
Finally, this post gives details on how to add a toolbar button to run your macro with one click.