Change SharePoint site name using a Feature - asp.net

I am running into a problem when creating a SharePoint 2010 Feature. What I am trying to do is:
Check to see if the site name is the same as the site title.
If it isn't, change the name (and therefore the URL) to match the title.
My code is as follows:
Private Sub ChangeSiteNameToMatchTitle()
_web = SPContext.Current.Web
If _web.Name <> _web.Title Then
_web.Name = _web.Title
_web.Update()
End If
_web.Dispose()
End Sub
This successfully changes the name so that it's identical to the site title, but it causes the Feature to crash at the end of it's activation cycle due to the fact that the site name (and therefore the URL) has changed.
The Feature appears to be trying to reload the ManageFeature.aspx page on the site that activated it, but since the URL has changed it cannot find the page any more.
Does anyone know of a workaround for this, or even if it's possible?
Many thanks!

I would make the Feature hidden and activate it outside of the UI using PowerShell.
Also, per best practice rule SPDisposeCheckID_220, you should not dispose SPContext.Current.Web:
SPContext objects are managed by the SharePoint framework and should not be explicitly disposed in your code. This is true also for the SPSite and SPWeb objects returned by SPContext.Site, SPContext.Current.Site, SPContext.Web, and SPContext.Current.Web.

Related

VS 2017 / ASP.net - Global functions not being recognized

I made the jump from VS 2010 (VB) all the way to VS 2017, and that may have been a mistake. I've already been slowed down with bugs, which I have reported. My latest concern is about accessing a global functions class that I have never had a problem with in VS 2010. I have reported it and it is in triage, but I wanted to make sure that something hasn't changed in the versions since 2010, hoping someone here can tell me.
Essentially what happens is that the global class, no matter how it is configured, is not recognized by any other class. Including a reference in a form class causes the IDE to tag it as an error. For example, the code in the GlobalFunctions.vb document:
Public Class GlobalFunctions
Public Function DecodeBase64(strEncoded As String) As String
Dim byt As Byte() = Convert.FromBase64String(strEncoded)
Return (System.Text.ASCIIEncoding.ASCII.GetString(byt))
End Function
Public Function EncodeBase64(strUnencoded As String) As String
Dim byt As Byte() = System.Text.Encoding.UTF8.GetBytes(strUnencoded)
Return (Convert.ToBase64String(byt))
End Function
End Class
and the calling methods from a form page:
If elemSetting.Attributes("name").Value = "LoginName" Then
Session("MailLoginName") = globalfunctions.DecodeBase64(elemSetting.Attributes("value").Value)
End If
If elemSetting.Attributes("name").Value = "LoginPass" Then
Session("MailLoginPass") = globalfunctions.DecodeBase64(elemSetting.Attributes("value").Value)
End If
Here the errors are being highlighted in the IDE:
And the error messages in the error list:
Understand, too, that I have tried as many variations of declarations as I can think of, such as "Public Shared Function," making the calling sub Shared, defining the global functions document as a Class or a Module, etc. Nothing works.
I've also tried placing the GlobalFunctions.vb class in the project's root directory and in a directory named App_Code, as was suggested in some blog posts around the net.
And since I have had no trouble like this with VS 2010, I assume it's a bug in 2017, which, as I said, I have reported. But I wanted to check with better minds than my own to see if I have overlooked something that may have changed somewhere between 2010 and 2017.
Can someone tell me if I am doing something wrong? Or maybe reaffirm for me that this is, indeed, a bug?
Thanks!
Try to delete and recreate your GlobalFunction.vb as maybe by renaming it in the past it didn't correctly correct everywhere in the project.
I think this is normal. You are using a Class and not a Module so you would need to declare a new instance either call like this:
Dim Globaler As New GlobalFunctions
If elemSetting.Attributes("name").Value = "LoginName" Then
Session("MailLoginName") = Globaler.DecodeBase64(elemSetting.Attributes("value").Value)
End If
If elemSetting.Attributes("name").Value = "LoginPass" Then
Session("MailLoginPass") = Globaler.DecodeBase64(elemSetting.Attributes("value").Value)
End If
Or use a Module and you wont need to declare a new instance.
Also if it still can't be accessed you should check the fact that maybe you just included the file to the solution without including it to the project
To Add new class:
Solution Explorer
Right Click your Project Name (above My Project)
Add
Class

Change URL in new Firebase (from May 2016)

Earlier when using Firebase, there was an option to use our own url like myapp.firebaseapp.com (including firebaseapp.com part). But from May 2016, when I create a project, it gets an auto-generated URL like my-app-1c75b.firebaseio.com, and I cannot find place to edit that (because 1c75b part in URL is not nice). I want to know is there any way to edit that like before?
Note - I don't want to use a paid domain like www.example.com. I just want to customize my Firebase URL as myapp.firebaseapp.com
When you create a project in the new Firebase console, it will indeed add a "random" code to the project name. There is currently no way to prevent this code in the new console.
When you upgrade an existing project from firebase.com into the new console, the app name will remain unchanged. So if you already have myapp.firebaseapp.com on a firebase.com project, you will keep that URL after importing/upgrading.
When creating a new project, you get an screen where you can enter the name.
In the textfield for project-id ou can enter a project-id.
your project-id needs to include a dash
when it doesn't, it will say something like, it is already used or it places the dash itself, with some custom characters.
The project-id itself is fixed, so you should create a new project and copy everything.
When you create your project the url is based on the project name you give. If your project name is "Foo Bar", your url will be https://foo-bar.firebaseapp.com (assuming it isn't already taken).
Last week Create Project window was showing possible firebase.com subdomain that will be assigned while you were typing project name. It's first come - first served basis so if you type a name already taken it automatically adds some character-number combination at the end.
Today same window doesn't show that while typing, you can only see it after you create your project and go to settings dashboard, there is no way to change given subdomain on the same dashboard.
Update 10.07.2017
I'm getting random hex number added from time to time, I can't always get plain name even if name is supposedly original one.
If you choose a name unique enough within Firebase, they will give you a domain for your app as in https://myapp.firebaseio.com.
I tried several times, sometimes it gives something like https://project-(long-random-number-sequence).firebaseio.com and other times something like what you've encountered. My personal experience shows if you give your app a name suffixed with "app" then you have a higher chance of being unique and getting the "nice" URL.
Scroll down in 'Manage Site' and create a new site, then deploy there.
You can't change your domain, but you can change the host! You can make as many sites as you want.

Open direct links to AX-objects or datasets from external application

Is there a way to open a specified document, eg "production order 123" or form, eg "purchase orders" in Ax2012 from an external application directly?
In detail, I'm looking for something similiar like AXPath, but this doesn't work with versions greater then 2009.
Is there any ( maybe included ) way to achieve this?
There is! It's using AX's drilldown functionality which uses AxHLink.exe to handle dynamics:// URLs, which are passed to the Classes\SysStartupCmd function. You could also create some custom code there if you wanted to launch the AX client executable directly.
My question I asked some while back should have a great deal of useful information in it here:
What handles dynamics:// URLs?
Some more can be found: http://technet.microsoft.com/en-us/library/aa834337.aspx
EDIT:
It sounds like you are confused or the posts weren't clear enough. I think you have 3 basic options.
Dynamics:// URLs are handled by AxHLink.exe and they only seem to handle drilldown, viewalert, and viewalertrule. So if you want to use Dynamics:// URLs, you will need to hi-jack those somehow. There is a pastbin from Jan in that other stack post.
Create a custom URI handler and event poller (lot of work) see http://axcoder.blogspot.dk/2010/10/how-to-open-form-in-running-ax-from.html
Extend SysStartupCmd and then instead of using Dynamics:// URLs, just call Ax32.exe -startupCmd directly and a parameter can be passed to your custom class.

Sitecore context in HttpModule

I created simple HttpModule, all what I need is just get is valid Sitecore.Context inside but during processing I see that my Sitecore.Context is some kind of default.
I can get Sitecore user that log in to Sitecore, etc.
How to fix it ?
I assume you have a Sitecore Context, but it is null or set to the wrong site or language.
You can change the context like this:
// switch to the preferred site
Sitecore.Context.SetActiveSite("yourSiteName");
// set the preferred database
Sitecore.Context.Database = Sitecore.Configuration.Factory.GetDatabase("master");
// set the preferred language
Language language = Sitecore.Globalization.Language.Parse("en");
Sitecore.Context.SetLanguage = (language, false);
You probably also want to switch back to the original settings after your processing is done. So it is wise to "save" the original settings in a variable so you can change them back afterwards
Take a look at John West's posts on Sitecore pipelines for some background on how the context is being established.
http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2011/05/All-About-Pipelines-in-the-Sitecore-ASPNET-CMS.aspx
and
http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2011/05/Important-Pipelines-in-the-Sitecore-ASPNET-CMS.aspx
The following blog post on creating and running custom pipelines should give you an idea how to implement your own pipeline.
http://adeneys.wordpress.com/2008/08/27/creating-and-running-custom-pipelines-in-sitecore/

CurrentWorkItem.ID is correct or not in workflow script editor?

I am using Tridion 2011 SP1, And I am creating workflow like start-->create-->Review-->publish--Stop.
I created and registered the class library, and invoke the C# method using VBscript (Script Editor of WF Tab) as given below.
Option Explicit
Dim workflowHandler
Set workflowHandler= CreateObject("CoreComponentWorkflow.WorkflowHandler")
If Not workflowHandler Is Nothing Then
Call workflowHandler.PublishComponent(Cstr(CurrentWorkItem.ID))
FinishActivity "Published to WIP"
End If
Set workflowHandler= Nothing
Is the above code is correct? I am sure I am able to create object using the below line.
Set workflowHandler= CreateObject("CoreComponentWorkflow.WorkflowHandler")
And currently I am publishing the current item only using the C# code, am calling the C# function as below.
Call workflowHandler.PublishComponent(Cstr(CurrentWorkItem.ID))
After publishing the item, I am finishing the activity using below.
FinishActivity "Published to WIP"
I have checked the above code directly in the server by hard coding the currentworkitem, it was working fine. But when I put the same code in vbscript editor, the item is not published.
Can any one suggest on this?
When you hardcode you might be adding the TCM ID directly so it is working properly, which means that CurrentWorkItem.ID is not the correct API call to get the Component ID. See Igor comment below to get the tcm id.

Resources