How can I access the Google Contact 'File As' field programmatically via the API? - google-api

I desperately need to access this field in order to develop a Google Contacts sync tool that predominately utilizes the company name as the NAME or FILE AS field, NOT First/Last.
I see it in the XML but no dice via the libraries. I'm using the .NET library.

I figured it out. Here's a little VB.NET code snippet in case anyone else needs to know how to manipulate values not directly exposed by the gData library. This returns the XML node (and creates first it if it doesn't exist). I actually change the value through the innerText property.
Private Function GetFileAsObject() As XmlNode
For Each ext As Object In _contactEntry.ContactEntry.ExtensionElements
If (ext.GetType() Is GetType(XmlExtension)) Then
If ext.XmlName = "fileAs" Then
Return ext.Node
End If
End If
Next
Dim doc As New XmlDocument
doc.LoadXml("<gContact:fileAs xmlns:gContact='http://schemas.google.com/contact/2008'></gContact:fileAs>")
Dim node As XmlNode = doc.DocumentElement
Dim newExt As XmlExtension = New XmlExtension(node)
_contactEntry.ContactEntry.ExtensionElements.Add(newExt)
Return node
End Function
This link helped immensely: http://code.google.com/p/google-gdata/wiki/UnderstandingTheUnknown

Related

Creating a view and agent in multiple databases

The problem I am encountering is that some of the messages are not accessible by the user ID file, I would like to skip these files instead of the agent crashing out. The error message received is as follows:
Using the view approach if this happened I was able to delete the document temporarily and re-run the agent but if there is a way to skip documents it would be a great help.
Thanks for the help guys.
Ok I have amended the code to a point where I am almost comfortable with it.
Sub Initialize
Dim s As New notessession
Dim db As notesdatabase
Dim view As notesview
Dim doc As notesdocument
Dim nextdoc As notesdocument
Set db = s.currentdatabase
If view Is Nothing Then
Set view = db.CreateView("Encrypted",{Encrypt="1"})
End If
Set doc = view.getfirstdocument
On Error Goto ErrorHandler
While Not doc Is Nothing
nextDocument:
Set nextdoc = view.getnextdocument(doc)
'The below loop is mandatory to ensure that all $File entries are unecrypted
Forall i In doc.items
If i.isencrypted Then
i.isencrypted=False
End If
End Forall
'Must have at least 1 field encrypted in order to call Encrypt method
Dim temp As New NotesItem(doc,"tempjunk","temp")
temp.IsEncrypted=True
Call doc.encrypt
Call doc.save(True, False)
'This portion can now remove the fields relative to encrypting the
'single token encrypted field.
Call doc.removeitem("$Seal")
Call doc.removeitem("$SealData")
Call doc.removeitem("SecretEncryptionKeys")
Call doc.removeitem("Encrypt")
Call doc.removeItem("tempjunk")
Call doc.save(True, False)
Set doc = nextdoc
Wend
Exit Sub
ErrorHandler:
On Error Resume nextDocument
Exit Sub
End Sub
The error handling is not playing nice;
On Error Resume nextDocument is showing up as an error.
I have tried suppressing all of the error warnings which seems to attempt to strip the encryption but I think they body of the messages is being destroyed as a result.
It is no problem to create an agent in a container database and let that agent access documents in all "target" databases and modify them accordingly - No need to copy that agent to all databases.
Only restriction: If the databases are on another server, then on the server security tab of the target server you have to enter the server with the container database as trusted server.
AND: If your agent runs longer than the allowed maximum run time for agents on the server, then it will be killed prematurely.
There is no need to create views in the target databases, you can use NotesDatabase.Search() to get the corresponding documents in the databases...
You can create views by copying them from another database. Say you create a view "Encrypted" in your db with the agent.
Then add a piece of code to get a handle of this view as a NotesDocument:
Dim dbThis As NotesDatabase
Dim viewTemplate As NotesView
Dim docView As NotesDocument
Set dbThis = s.currentDatabase
Set viewTemplate = dbThis.getView("Encrypted")
Set docView = dbThis.Getdocumentbyunid(viewTemplate.Universalid)
In the agent loop, test if view Encrypted exists, if not copy the "view template":
Set view = db.getview("Encrypted")
If view Is Nothing Then
Call docView.Copytodatabase(db)
Set view = db.getview("Encrypted")
End If
Finally, if you insist, a similar procedure might be used to copy the agent to all databases, but for me the idea of running the agent in one db sounds better.
Edited: In the view of full disclosure - of course you can create a view (I guess that was the original question).
If view Is Nothing Then
Set view = db.Createview("Encrypted", {Encrypt="1"})
End If
Or do one-shot dbSearch suggested by Torsten, with a good re-mark of Richard - if you intend to run your code several times - say if encrypted documents might get created again or re-encrypted, rather go for the view.
My method is a bit old fashioned (pre-dates availability of createView) and works well if you need more than selection formula, so you can pre-build a complicated view for re-use.
Performance-wise: whatever method you will choose either creating view using createView or copying from other db or doing dbSearch there is going to be a certain slow-down while the view gets built or dbSearch executes. Karl-Henry's approach will avoid this search/view build, but will be relatively slow if there are not many encrypted documents.
Whichever method you choose - here is a small tip to boost performance. Make your loops like this to release memory as you go; for example, assuming Karl-Henry's approach:
Dim doc1 as NotesDocument
Set doc = col.GetFirstDocument()
Do Until doc Is Nothing
Set doc1 = col.GetNextDocument(doc)
formname = doc.GetItemValue("Form")(0)
If IsElement(exclude(formname))=False Then
Call RemoveEncryption(doc) '*** Your function to remove encryption
End If
' releasing memory when processing thousands of documents improves performance and avoids crashes
Delete doc
Set doc = doc1
Loop
Now again, as you are talking only about migration (so one shot) of 20+ databases, the speed or implementation details should not be that critical.
If you have to process all (or almost all) documents in each database, you can use db.AllDocuments. It is more efficient than using db.Search() with an #All formula.
If you want to exclude certain documents, perhaps based on the form name, I would build a list of forms to exclude, and then use IsElement to check each document being processed against that list.
Dim exclude List As Boolean
exclude("FormA")=True
exclude("FormB")=True
Set col = db.AllDocuments
Set doc = col.GetFirstDocument()
Do Until doc Is Nothing
formname = doc.GetItemValue("Form")(0)
If IsElement(exclude(formname))=False Then
Call RemoveEncryption(doc) '*** Your function to remove encryption
End If
Set doc = col.GetNextDocument(doc)
Loop
Something like that. By the way, you can create the list as any data type. I just choose Boolean as it is a small data type, and that it makes the code easier to read. The IsElement() function just check if the element exists, it does not use the value you set.
You would wrap the code above in a function and call it once per database.
Appended answer, based on additional info in original question:
That should not be hard, just add error handling to your code.
Before you start to loop throung the document:
On Error Goto errHandler
Before you get the next document in the loop:
nextDocument:
At the end of your code:
Exit Sub
errHandler:
Resume nextDocument
End Sub
Try that.

Outlook 2007 Add-In - mailItem.To only available after hitting a breakpoint and looking at value manually

I am making an outlook plugin in visual studio and part of it requires gathering the recipients/subject/body content. I am able to gather the subject and body without problem but accessing mailItem.To I always find it's blank.
body = mailItem.Body
subject = mailItem.Subject
Dim readtest As String = mailItem.To
Is the code I am using, and what makes it worse is that if I put a breakpoint in before trying to populate readtest and then I manually just look at the mailItem.To value and resume or step through the code it will work just fine.
Does anyone know how I can get this working properly?
You could try to get the same functionality with mailItem.Recipients property.
It returns IEnumerable. Recipient object have a Name member so basically you could do the following (It's in C# but i think you could figure it out with vb):
string recipients = string.Empty;
foreach (Outlook.Recipient r in mailItem.Recipients)
{
recipients += r.Name + ";";
}
You should get the same result as if you use mailItem.To

Outlook VSTO is it possible to use the address book control?

I need to mimic the adress book control in an Outlook VSTO project. It would be much simpler to use the real control, isn't it?
So, do you know a way to expose the address book control, and get what's selected within, of course?
Edit: Never mind, re-creating a basic version of the control will be way easyer.
Solution: third party Redemption library offer this feature.
RedemptionLoader.RDOSession.AddressBook.ShowAddressBook(...)
You don't need to use a third party addin. you can do it with this:
http://msdn.microsoft.com/en-us/library/office/ff868361.aspx
this code below is in VBA but you can easily convert it to C#:
Sub SelectRecipients()
Dim oMsg As MailItem
Set oMsg = Application.CreateItem(olMailItem)
Dim oDialog As SelectNamesDialog
Set oDialog = Application.Session.GetSelectNamesDialog
With oDialog
.InitialAddressList = _
Application.Session.GetGlobalAddressList
.Recipients = oMsg.Recipients
If .Display Then
'Recipients Resolved
oMsg.Subject = "Hello"
oMsg.Send
End If
End With
End Sub

ms access linked image relitive path

I have an Image object.
I have the Picture type set to linked, so I can change the picture if I want.
I have the Picture property set to the picture name.
I would think that access would use relitive addressing and simple looking in the current directory for the image. But it does not and I get an error telling me it cannot find the picture.
Anyone have a solution? (Other than setting the Picture type to embedded or using the full file address?)
Thanks!
Update:
Tried this:
Private Sub Form_Load()
Dim file As String
file = CurrentDb().Name
file = Replace(file, ".mdb", ".bmp")
Me.Image46.Picture = file
End Sub
It works, except I still get the error message. I click O.K. and it works. Just need the error message to go away.
SOLUTION: Use the above code (or the code posted in the answer below) and then set the 'picture type' to "embedded" and then delete the 'picture' field so that it says "(none)".
Save and run.
It should work.
THANKS!
You could set the property on the forms OnLoad event like this
Me.imgMy_image.picture=getDBPath & “mypicture.bmp”
Here is the getDBPath function
Public Function GetDBPath() As String
Dim strFullPath As String
Dim I As Integer
strFullPath = CurrentDb().Name
For I = Len(strFullPath) To 1 Step -1
If Mid(strFullPath, I, 1) = "\" Then
GetDBPath = Left(strFullPath, I)
Exit For
End If
Next
End Function
Before anyone comments yes I know in access 2000 and above you can use currentproject.path but I’m stuck in the land that time forgot so need that custom function, it still works with later versions of access
Current folder depends of the way you open database in Access. At least, if you open it thru "File-Open", current folder changes to the folder of MDB file. But if you open via double-clicking MDB in explorer, it does not.

How do I write a 301 redirect taking a portion from the middle of the old url and using it on the end of the new?

I need to redirect my old cart links to the new site's search
Here's an example:
old url:http://www.example.com/servlet/the-1736/Festo-Line-Acuator-DNC-dsh-100-dsh-150-dsh-PPVA-dsh-Q/Detail
what new should look like: www.example.com/cart/index.php?dispatch=search.results&q=Festo-Line-Acuator-DNC-dsh-100-dsh-150-dsh-PPVA-dsh-Q
So on my old URL's they would always originate from the subdirectory "servlet", the next piece is a variable category (in this case "the-1736"), then the piece I want to use in the new url string, then everything after that next slash should be ignored.
I am assuming he is using PHP, as that is the extension on the second URL. I am also assuming a J2EE back-end for the old URL because of the "servlet" part.
I am not an expert in url-rewrite, but it seems that you should be able to do that. I guess it depends on the actual back-end, assuming Apache based PHP. It also depends on if the replacement is as simple as it seems from your question.
Also, is path servlet/the-1736 static? Not a PHP expert either, but you should be able to use a file path manipulator to take the path after the static text, and before the Detail directive and put it into the query string for the new URL.
Here's how I do it in VB.NET
Protected Sub OnBeginRequest(ByVal sender As Object, ByVal e As EventArgs)
'Force Removal of WWW
Dim application As HttpApplication = TryCast(sender, HttpApplication)
Dim url As Uri = application.Context.Request.Url
Dim hasWWW As Boolean = UrlRegex.IsMatch(url.ToString())
If hasWWW Then
Dim newUrl As [String] = UrlRegex.Replace(url.ToString(), [String].Format("{0}://", url.Scheme))
application.Context.Response.Status = "301 Moved Permanently"
application.Context.Response.AddHeader("Location", newUrl.Replace("default.aspx", ""))
End If
End Sub
The example below is in my Global class where I redirect to a non WWW url. You can modify it to your liking, the 301 redirect is the same.
EDIT: Answer above was given before the OP clarified the technology they were using

Resources