Microsoft Graph userprincipalname C# - c#

I am trying to auto increase the number after _ on userprincipalname but it dosen't works.
My code: https://gist.github.com/Erraticoye/b52e4e92102d80cc0349dbb297a93e79
Sorry for bad English. I tried try and catch(you can see in the code)

Had a quick look at your code. Seems you initialize the "i" variable in line 49 after a foreach loop.
Have you tried initializing the "i" variable at the beginning of your code and then have the foreach increment the value?
Or just move the int i = 2; before line 42 at least?
My guess is that the number is always 2 after the underscore.

If you are looking for the changing the password or updating it, the following code:
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var currentPassword = "xWwvJ]6NMw+bWH-d";
var newPassword = "0eM85N54wFxWwvJ]";
await graphClient.Me
.ChangePassword(currentPassword,newPassword)
.Request()
.PostAsync();
For more information: https://learn.microsoft.com/en-us/graph/api/user-changepassword?view=graph-rest-1.0&tabs=csharp#request
Hope this helps.

Related

replace \\ to \ when using # symbol

Issue with replacing text...username is 'JoelFarrell'
userName = #"WILD\" + userName; // returns "WILD\\JoelFarrell"
I only want "WILD\JoelFarrell" so ive tried to replace it
userName = userName.Replace("\\", #"\");//this does not work
userIdInDNNUsersTable = DbContext.Users.Where(x => x.Username == userName).Count();//returns 0 results because it is searching for 'WILD\\JoelFarrell' where as if it was searching for 'WILD\JoelFarrell' I would get what I am looking for
Any one have any ideas? thanks for any replies
If i test it in quick watch and change userName = "WILDFIRE\JoelFarrel" it says unrecognized rewscapce sequece. but if I search SQL for the record in the db `
select * FROM [Dot].[dbo].[Users]
where username LIKE '%WILDFIRE\JoelFarrell%'`
returns the result I am looking. So how do I get this result in code?
Actually
userName = #"WILD\" + userName; // returns "WILD\\JoelFarrell"
Returns
WILD\JoelFarrell
Its just that the debugger is displaying it as \\ (very unhelpfully IMHO)
When you look at userName in the debugger, you're seeing the escaped version. Hit the magnifying glass beside the watch or tooltip. That will give you the non-escaped version.

c# compiler error with Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition;

I have the below code which is for modifying a textframe in a word document at runtime.
This is in a .NET Windows Forms app.
var oShapes = oWord.ActiveDocument.Shapes;
var titleShape = oShapes["Title"];
var myWord = new Microsoft.Office.Interop.Word.Application();
titleShape.Height = myWord.InchesToPoints(1.75F);
titleShape.Width = myWord.InchesToPoints(0.45F);
titleShape.RelativeHorizontalPosition = Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition;
titleShape.RelativeVerticalPosition = Microsoft.Office.Interop.Word.WdRelativeVerticalPosition();
titleShape.Left = 4.35F;
titleShape.Top = 17.5F;
titleShape.TextFrame.WordWrap = 0;
titleShape.LockAnchor = 1;
var sTitle =string.Empty;
titleShape.TextFrame.TextRange.Text = DocumentType; // sTitle;
titleShape.TextFrame.AutoSize=-1;
Unfortunately I must have got it wrong because Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition; is showing as an error in VS 2010 (and also on the line below.
What is the correct way to use word enumerated constants like that in c# through Office Interop?
remove the parentheses:
titleShape.RelativeVerticalPosition = Microsoft.Office.Interop.Word.WdRelativeVerticalPosition;
you also don't say what the compilation error is.
The problem is that you are calling the property as if it was a method. Remove the paranthesis at the end and you should be done.
titleShape.RelativeVerticalPosition = Microsoft.Office.Interop.Word.WdRelativeVerticalPosition;
Hope this helps.
I found it, I was calling the enumeration name, rather than the enumerated constant.
So Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition
should be
Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;
(plus I was using brackets thinking that was the problem)

Regular expression to get facebook profile

I tried to check matches facebook url and get profile in one regular expression:
I have:
http://www.facebook.com/profile.php?id=123456789
https://facebook.com/someusername
I need:
123456789
someusername
using this regular expression:
(?<=(https?://(www.)?facebook.com/(profile.php?id=)?))([^/#?]+)
I get:
profile.php
someusername
Whats wrong?
I advise you to use the System.Uri class to get this information. It does the difficult work for you and can handle all sorts of edge cases.
var profileUri = new Uri(#"http://www.facebook.com/profile.php?id=123456789");
var usernameUri = new Uri(#"https://facebook.com/someusername");
Console.Out.WriteLine(profileUri.Query); // prints "?id=123456789"
Console.Out.WriteLine(usernameUri.AbsolutePath); // prints "/someusername"
I agree with others on using System.Uri but your regex needs two modifications to work:
\ in (profile.php\?id=)
(\n|$) at the end
(?<=(https?://(www\.)?facebook\.com/(profile\.php\?id=)?))([^/#?]+)(\n|$)
The following example writes the query ?id=123456789 to the console.
Uri baseUri = new Uri ("http://www.facebook.com/");
Uri myUri = new Uri (baseUri, "/profile.php?id=123456789");
Console.WriteLine(myUri.Query);
Hope this Helps!
Try this:
https?://(?:www.)?facebook.com/(?:profile.php\?id=)?(.+)
or
https?://(?:www.)?facebook.com/(?:profile.php\?id=)?([^/#\?]+)

Using GeocodeQuery with Canadian Postal Codes

I am having an issue with Windows Phone 8 Geocoding. Using Microsoft.Phone.Maps.Services.QuerycodeQuery, if I use a full Canadian Postal Code (M5G 1Z4) I get no results. If I use only the first 3 characters (M5G) I get the expected results.
I am not doing anything specific with the data, just passing it to Microsoft for geocoding. Is there a specific reason behind this or is there another way to lookup locations?
Code:
Geocode = new GeocodeQuery()
{
SearchTerm = LocationString,
GeoCoordinate = UserCoordinates ?? new GeoCoordinate(),
MaxResultCount = 1
};
Geocode.QueryCompleted += GetStringLocation_QueryCompleted;
Geocode.QueryCompleted += CleanupGeocode;
Geocode.QueryAsync();
Although this doesn't address the limitation that appears to be in the mapping service's geocode function it is a little workaround that works for me...
When the GetStringLocation_QueryCompleted function returns 0 results I run a regex to check if the search is a valid postal code. If it is one, then I grab the first 3 characters and re-run the geocode.
One thing to make sure of with this approach is that you check to make sure the geocode is not running (IsBusy) when the secondary dispose function is called (if you do it in a separate function)
Regex (Utility.IsPostalCode):
Regex reg = new Regex("^[ABCEGHJ-NPRSTVXY]{1}[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[ ]?[0-9]{1}[ABCEGHJ-NPRSTV-Z]{1}[0-9]{1}$",
RegexOptions.IgnoreCase | RegexOptions.Compiled);
return reg.IsMatch(Input);
Within GetStringLocation_QueryCompleted
if (e.Result.Count == 0 && Utility.IsPostalCode(((GeocodeQuery)e.UserState).SearchTerm))
{
if (Geocode != null && Geocode.IsBusy)
Geocode.CancelAsync();
GetStringLocation(((GeocodeQuery)e.UserState).SearchTerm.Substring(0, 3));
}
GetStringLocation would be the function that contains the code that is in the question which accepts a string.

VisitClassDeclaration node.Identifier in Roslyn

How can I find what line number in the source file the declaration was found on?
Disclaimer: I work for Microsoft on the Roslyn team.
You can use the ISyntaxTree.GetLineSpan() method to convert to a line number. For example, given an ISymbol "symbol", you can get the start location of the first definition with:
var loc = symbol.Locations.First();
var lineSpan = loc.SourceTree.GetLineSpan(loc.SourceSpan,
usePreprocessorDirectives: false);
var line = lineSpan.StartLinePosition.Line;
var character = lineSpan.StartLinePosition.Character;
From the title, it looks like you're starting with a SyntaxNode, so you can just use the Span property directly.

Categories