How to clone a UserPrincipal object in VB.NET - vb.net

I'm trying to create a new User in Active Directory from a VB.NET application. Most fields will be identical to an already existing "template" user, except things like Name, SurName, Email, SamAccountName, etc.
So I want to copy or clone this template User, assign the few fields with a new/different value and then save this new user in Active Directory. I'd like to avoid having to manually assign who-knows how many properties from my template to the new User and maybe forget something along the way..
Is there not a way to do that? I found something about using DirectoryEntry.CopyTo(), but I simply get a "Not implemented" error, and anyway I doubt this is the right direction (Unsure how to use this class together with a UserPrincipal object)
Should I be using a different class than System.DirectoryServices.AccountManagement.UserPrincipal to save my new user in the AD? Do I have the wrong approach?
Any help will be appreciated :)

If you look at the source code for DirectoryEntry.CopyTo, it calls:
newParent.ContainerObject.CopyHere(Path, newName)
And ContainerObject is of the type IADsContainer. If you look at the documentation for IADsContainer.CopyHere, it says (under Remarks):
The providers supplied with ADSI return the E_NOTIMPL error message.
ADSI is "Active Directory Service Interfaces". So the short answer is that it just won't work with AD objects.
There is no way to do what you want. You will have to manually assign each attribute you want to copy.

Related

Get MS Project Title (Not Name)

I need to get the Title of a project rather than the name of it. This can be done using the ProjectSummaryInfoEx method for the application object but I'm not sure how to get this line to return the value I need. Without any commands, it simply opens up the Summary info dialog box, and any inputs I provide come back as an invalid argument.
Any help anyone can provide would be greatly appreciated.
I suggest using:
ActiveProject.BuiltinDocumentProperties("Title")
or a property of the Project object such as:
ActiveProject.Name
References: Application object, Project object, BuiltinDocumentProperties
In addition to Rachel's answers, you can also use this:
ActiveProject.Tasks.UniqueID(0).Name
UID zero will always be the project summary task, and the name property will be the title of the project.

Graphql and access to Types Properties depending on some logic

I am new to Graphql and some things still confuse me.
I am working on a project, similar to Todo List.
User may have multiple todo items, some of item's properties must be visible to owner only, some should be public.
So far I came up with two ideas:
1) First is to create two separate types, something like:
ToDoType {
id
name
complete
}
ToDoPrivateType {
id
name
complete
colorGroup
createdAt
...other private properties
}
And access
- ToDoType from root query user {...} and everywhere else, except
- viewer {...} where I will use ToDoPrivateType
It will work but looks a little like double-work,
plus if I retrieve todo lists from standard user root query I will not be able to pull private properties for user's own user.
2) I can also provide access to all properties and set to null properties to which a random user should not have access (like createdAt of other's users) but it also does not look right.
Hope what I am asking is not too confusing.
Do these approaches make sense?
Is there a better way to control access to some properties?
Thanks!

MVC user's full name in Url, how to handle duplicates

I want to setup the following url in my MVC4 website, using the user's full name in the url:
http://www.myapp.com/profile/steve-jones
I have setup the following route in Global.asax:
routeCollection.MapRoute(
"profile", "profile/{userName}",
new { controller = "myController", action = "profile", userName = string.Empty
});
And I can take the parameter 'steve-jones' and match it to a user with matching name. My only problem though is, what if there is more than one 'Steve Jones', how can I handle this?
Does anyone know of a workaround/solution to this so that I can use a user's full name as part of the url and still be able to retrieve the correct user in the controller method?
Am I forced into including the user's id with the url (something that I do not want to appear)?
The usual way of handling this is by appending a number when creating the profiles. So if "steve-jones" is already a name in the database, then make the user's display name "steve-jones2". You basically have to insist that all profile urls are unique, which includes updating any existing database and account creation code.
Alternatively (and/or additionally), if two same names are found then have the script reroute to a disambiguation page where the user is presented with links and snippet of profile info of the many existing Steve Joneseses so they can go to the full correct profile.
Another way of handling it is by giving all user profiles an additional numeric code on the end. At my university all logins are based on name, so they give everyone pseudo-random 3-digit extensions so that they are safe as long as they don't get 1000 people with the exact same names :)
Some people might be happier being steve-jones-342 if there is no steve-jones or steve-jones1, if you're concerned.

Unable to detect the selected FileTypeChoice from FileSavePicker

I would like to let the user choose a save option while selecting a file type. The selection works fine as in the below example. However after the user has selected a file type to be saved, I have not found a possibility to check which type he has selected.
Please note: Both file type choices have the same extension. The difference between the two is the display name.
var fsp = new FileSavePicker();
fsp.FileTypeChoices.Add("my file type", new List<string> {".extension"});
fsp.FileTypeChoices.Add("my file type (special)",new List<string>{".extension"});
StorageFile sf = await fsp.PickSaveFileAsync();
// How to know here which FileTypeChoice the user has selected
Has anyone an idea how I can get the selected FileTypeChoice?
I don't think you can. The problem here is that the only difference between the two is the display name. I'd highly recommend using similar but distinct file extensions. What you have here is a distinction without any evidence. This makes it impossible for either the system or the user to distinguish between Type A and Type B.

What are the Aweber API Variables $account_id and $list_id?

You can check here:
https://labs.aweber.com/docs/code_samples/subs/create
The script to add a new subscriber to the list via api requires those two pieces info...only I cannot figure out for the life of me what those two variables are!! I've beaten through every little aspect of my Aweber Subscriber Account, AND my Aweber Labs account...and I can't find any reference to either of those variables anywhere. I've submitted some tickets to them, and haven't gotten any response yet.
Does anyone have any ideas here? I've tried my account names, my list names, to no avail!
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Okay, I've got it! You can get the values of both of these variables by dumping some other variables in the aweber api after making certain api calls.
get the account id first:
$account = $aweber->getAccount($accessKey, $accessSecret);
then vardump or print_r $account.
next we get the list id:
$account = $aweber->getAccount($accessKey, $accessSecret);
$list_url = 'https://api.aweber.com/1.0/accounts/<id>/lists';
$lists = $account->loadFromUrl($list_url);
then vardump or print_r $lists.
And you are all set! I'm so happy I figured this out, it freakin took long enough. Hopefully this saves some one a bit of time.
I too have agonized over finding the $list_ID, so went to deactivate the list, and create a new one, and "discovered" that if you hover over the Deactivate button, you get a url you can copy, and this gives both %account and %list Ids
https://www.aweber.com/users/lists/deactivate/$accountID/$lisID
like this....
https://www.aweber.com/users/lists/deactivate/123456/123456
Hopefully this will help make someone as it is a super easy solution
The proper answer is Anne Allen's one, but...
Check the return of the /accounts endpoint. It should return the same account id as you detected in the link, but I had cases they were different (strange, isn't it?). Use the account id returned by the /accounts endpoint and other endpoints to retrieve lists, subscribers, etc. will start to work. It's like if some accounts have two ids, one partially works and the other fully works.
Let me tell you how to get $list_id value... login into your AWeber account and then create a new list copy only integer value from list's name.
At first, login.
1) click Reports>Settings. Your account ID will be displayed in the box,example: ?id=XXXXX
2) click List Options>List Settings. There you will see the list ID under the name.
p.s. To add subscriber, you can use this - Automatically add into aweber list