Check if cookie exists #2 - vb.net

Trying to start with VB.Net and having problem
We have such a Class in C#.
How to check if cookie exist? Exactly, how to set input object "Cookie" for a function CookieExist? How to create it using GeckoFx?
For example, how to find cookie with the name "Test2"?
Please, make an example.
I'm going crazy with VB.Net
P.S. I rarely write to forums if can find info on my own but VB.Net have too few examples in the net. ;/

I think the code below will help you:
Dim cookieValue As String = "Value of cookie"
Dim cookieName As String = "CookieName"
Dim realCookie As HttpCookie = HttpContext.Current.Request.Cookies.Get(cookieName)
If IsNothing(realCookie) Then
HttpContext.Current.Request.Cookies.Add(New HttpCookie(cookieName, cookieValue))
End If

Related

VB.NET Get the V variable from a youtube url

I am writing a program to play videos from the internet in it.
for the user to get the video they have to paste a url in E.G. https://www.youtube.com/watch?v=5xniR1GN69U that url works but this one https://www.youtube.com/watch?feature=c4-overview&list=UUOYWgypDktXdb-HfZnSMK6A&v=5xniR1GN69U dosnt
this is my currunt code
how do i get it to just the v varibale from the url
Your querystring looks like "?v=5xniR1GN69U" the first time and "?feature=c4-overview&list=UUOYWgypDktXdb-HfZnSMK6A&v=5xniR1GN69U" the second time. You could have figured that out by yourself by simply debugging and checking your variables, since it doesn't even reach the code in the if block... Making a screenshot doesn't help people to figure out what's wrong with your code.
You might want to use Regex to parse the id Regex.Match(str, "v=(\w+)").Groups(1).Value
Just request the parameter v?
Request("v")
or
Request.Querystring("v")
EDIT
If in winforms. You can apply as suggested by #Markus
Try it like this
Dim querystring As String = url.Query
Dim myMatches As MatchCollection
Dim MyRegEx As New Regex("v=+(\w+)")
myMatches = MyRegEx.Matches(querystring)
For Each Row In myMatches
AxShockFlashMovie1.Movie = "https://www.youtube.com/v/" & Row.ToString() & ""
Next
You will also need to include
Imports System.Text.RegularExpressions
I've used HttpUtility.ParseQueryString in the past for something similar. Don't forget that youtube also offer tiny version of the urls with http://youtu.be/???

Reading and changing fields in SAP with RFC via VB .NET

I'm currently trying to figure out the basics of remote function calls via vb .NET. I feel pretty helpless however, because their just isn't any useful documentation for the most simple of tasks.
What I'm trying to do atm is starting the transaction CO13, write the confirmation number in the appropriate field and cancel the order. Even this simple tasks turned out to be a pain in the ass. I'm still not sure how to access and modify the contents of a specific field. There are some examples with tables for excel in the net, but hat's about it. What I have so far is this (login is working and in another function):
Public Function stornieren() As Boolean
Dim ordernr As String
Dim confirmationnr
Dim confirmation As Object
Dim R3 As Object
Dim CO13 As Object
Dim result
R3 = CreateObject("SAP.Functions")
ordernr = TextBox3.Text
confirmationnr = TextBox4.Text
CO13 = R3.Add("RFC_CALL_TRANSACTION_USING")
CO13.exports("TCODE") = "CO13"
CO13.exports("MODE") = "S"
confirmation = CO13.exports("RUECK")
confirmation.value = confirmationnr
result = CO13.call
End Function
RUECK is the Field Name. I want to write the value of "confirmationnr" into the field RUECK. "confirmation.value = confirmationnr" throws the error message "the object variable could not be determined" and "NullReferenceException" was not handled. Sounds to me like the object is empty.
Thanks in advance.
EDIT: Now trying via BAPIs and particularly BAPI_PRODORDCONF_CANCEL. I have no idea about the syntax though. Any help would be appreciated.

How do I pass ItemSpec into GetBranchHistory()?

I'm trying to get information about specific branches in TFS, so to start, I'm trying to create a variable to assign as a BranchHistoryTreeItem. However, when I pass in the ItemSpec, I'm getting an error on Spec (not the definition, but where it's passed into GetBranchHistory):
Value of type 'Microsoft.TeamFoundation.VersionControl.Client.ItemSpec' cannot be converted to '1-dimensional array of Microsoft.TeamFoundation.VersionControl.Client.ItemSpec'
I understand the error, but I'm not entirely sure why it throwing it. Isn't this data type exactly what it's looking for? I believe I have the ItemSpec declared correctly, but I'm a bit lost here. Can anyone offer some advice on why I'm getting this? Code:
Sub GetBranchInfo()
Dim tfs As New TfsTeamProjectCollection(Common.BuildServerURI)
Dim Version = tfs.GetService(Of VersionControlServer)()
Dim Spec As New ItemSpec("$/Project1", RecursionType.None)
Dim BranchHistory As New BranchHistoryTreeItem(Version.GetBranchHistory(Spec, VersionSpec.Latest))
End Sub
GetBranchHistory takes an array of ItemSpecs.
My VB is a little rusty, but I think you want something like:
Dim Spec As New ItemSpec("$/Project1", RecursionType.None)
Dim Specs(1) = new ItemSpec() {Spec}
Dim BranchHistory As New BranchHistoryTreeItem(Version.GetBranchHistory(Specs, VersionSpec.Latest))

New WebProxy to read from list box VB.net

I am using http web requests and want it to use different proxies.
This is my starting point:
Dim myproxy As New WebProxy("http://1.1.1.1:80")
I would like to populate the address section using an item from ListBox.
VB does not let me do it, because I am trying to convert a string to an address data type.
Is there a way?
If you managed to solve your problem with the C# code you posted, VB could look like this:
Dim prx As String = "http://" & lstProxy.Items(x)
Dim myProxy As New WebProxy(prx)
And if you write same in C#, there is hardly any difference.
Ok - could not figure it out! But have since switched to C#.net and it's all good.
I've handled it like this:
string front = "http://";
string prx = front + lstProxy.Items[x].ToString();
WebProxy myProxy = new WebProxy(prx);
So, top advice from me is to get C#.Net. Feel free to comment on this if any help is needed.

How to set user "logon to" AD attribute in VB.NET

I'm working on upgrading a solution in VB.NET that is heavily based on Active Directory. As of now, I'm trying to add a PC restriction to a new AD User upon user creation. Essentially, I need to update the Logon To attribute to include 1 or more PCs, how do I go about doing this?
I learned that I am interested in the IADsUser property "LoginWorkstations" (thanks to http://msdn.microsoft.com/en-us/library/Aa746340). As of now, I have code that can fetch this attribute from any AD user, but I cannot set it.
Here is the code I have to fetch the attribute:
Dim userADObject As new DirectoryEntry(ADPath)
Dim logonToPC as String = userADObject.InvokeGet("LoginWorkstations")(0).ToString
That will fetch the first restricted PC (if there is one) and save it in logonToPC and will look something like "PC10000"
That works great, so intuitively I would assume something like this would work:
Dim userADObject As new DirectoryEntry(ADPath)
Dim args() As Object = {"PC100001"}
userADObject.InvokeSet("LoginWorkstations", args)
But it doesn't work... It just throws a rather unhelpful exception.
I've tried testing this approach with a different attribute and it works just fine. Not much out there on Google either unfortunately...
Any help would be greatly appreciated.
You should be able to do this fairly easily - also: note that you should use the userWorkstations LDAP attribute (see note here) - this is multi-valued, e.g. it allows multiple entries.
Dim userADObject As new DirectoryEntry(ADPath)
userADObject.Properties("userWorkstations").Add("PC001")
userADObject.Properties("userWorkstations").Add("PC002")
userADObject.Properties("userWorkstations").Add("PC003")
userADObject.CommitChanges()
If you have the necessary permissions to update Active Directory, that should basically do it, I think.
Found the solution that works. I took marc_s's code and modified a bit to work properly. here's what I have:
Dim userADObject As New DirectoryEntry(Me.ADPath)
'Grab the previous restriction, because we may have to clear it first in the future
Dim priorRestriction As String = userADObject.Properties("userWorkstations").Value
If priorRestriction = "" Then
'Simply add
userADObject.Properties("userWorkstations").Add("PC001,PC002")
Else
'Important - We have to clear the old restriction before adding the new
userADObject.Properties("userWorkstations").Remove(priorRestriction)
'Now add the new restriction
userADObject.Properties("userWorkstations").Add(priorRestriction & ",PC003")
End If
'Commit!
userADObject.CommitChanges()
Something that gave me some pretty good grief what that I you can't have a space in the string being added. Example: .Add("PC001, PC002") has to be .Add("PC001,PC002")