Hi, I'm trying to do the same thing, to use localization from a scheduled task.
I tried the way you suggest, with no luck, here is the code:
OPTION 1:
Private Function GetLocalizedString(ByVal key As String, ByVal portalId As Integer) As String
Dim objPortalController As PortalController = New PortalController
Dim objPortalInfo As PortalInfo = objPortalController.GetPortal(portalId)
Dim objPortalSettings As PortalSettings = GetPortalSettings(objPortalInfo)
Return Localization.GetString(key, SharedResourceFile, objPortalSettings, objPortalInfo.DefaultLanguage)
End Function
Private Function GetPortalSettings(ByVal objPortalInfo As PortalInfo) As PortalSettings
Dim p_Alias As PortalAliasCollection = New PortalAliasCollection
Dim strAlias As String = String.Empty
Dim ctlPortalAlias As PortalAliasController = New PortalAliasController
p_Alias = ctlPortalAlias.GetPortalAliasByPortalID(objPortalInfo.PortalID)
For Each key As String In p_Alias.Keys
If Not String.IsNullOrEmpty(key) Then
strAlias = key
Exit For
End If
Next
'Throws an exeption in the following line
Dim p_Settings As PortalSettings = New PortalSettings(objPortalInfo.HomeTabId, p_Alias.Item(strAlias))
Return p_Settings
End Function
OPTION 2:
Private Function GetLocalizedString(ByVal key As String, ByVal portalId As Integer) As String
Dim objPortalController As PortalController = New PortalController
Dim objPortalInfo As PortalInfo = objPortalController.GetPortal(portalId)
'Throws an error in the next line
Return Localization.GetString(key, SharedResourceFile, objPortalInfo.DefaultLanguage)
End Function
Any help will be appreciated