How to change the calendar type in dateTimePicker? - datetimepicker

i try to change the calendar type in dateTimePicker from gregorian to hijri but i cant cuz the system calender type it's gregorian .
i try this code
CultureInfo ci = new CultureInfo("ar-SA");
DateTimeFormatInfo info = ci.DateTimeFormat;
dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = info.ShortDatePattern + " " + info.ShortTimePattern;
but not working !?
how i can change it in my App?

From MSDN:
The DateTimePicker control only supports Gregorian calendars.
But you can create a custom calendar, check out these articles (C#):
Windows Hijri Calendar
ASP.NET DatePicker User Control (Hijri / Gregorian)
How to create a Hijri Calendar control in .Net Framework 2.0

DatetimePicker use the system calendar to change it you need to change the registry subkey
Imports Microsoft.Win32
Dim reg As Registrykey=Registry.CurrentUser.OpenSubkey("Control Panel\International\🌎🌍🌏",True)
reg.SetValue("Calendar","Gregorian")
Dim sreg As Registrykey =Registry.CurrentUser.OpenSubkey("Control Panel\International", True)
sreg.SetValue("sCalendar","GregorianCalendar")
You can choose any calendar in calendar list of your windows but make sure to write the proper spelling
It is important to change the cultureinfo to the culture using the specified Calendar

replace "Gregorian" and "GregorianCalendar" with the name of the calendar you want to use .
spelling must be correct
your current system culture must support the calendar you want to use.

Imports Microsoft.Win32
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Regk1 As RegistryKey = Registry.CurrentUser.OpenSubKey("Control Panel\International\🌎🌏🌍", True)
Regk1.SetValue("Calendar", "Gregorian")
Regk1.Close() Dim Regk2 As RegistryKey = Registry.CurrentUser.OpenSubKey("Control Panel\International", True)
Regk2.SetValue("sCalendar", "GregorianCalendar")
Regk2.Close()
Dim Formatregk As RegistryKey = Registry.CurrentUser.OpenSubKey("Control Panel\International", True)
Formatregk.SetValue("sShortDate", "dd/MM/yyyy")
End Sub
Replace the "Gregorian" And "GregorianCalendar" with Calendar you want to use but be sure the new calendar is supported by the current culture

Related

VB.Net RecycleBin is not declared

I refer to this post How to retrieve the 'Deletion Date' property of an Item stored in the Recycle Bin using Windows API Code Pack?
I refer to the answer by #ElektroStudios. I am trying to run that code. My knowledge of VB.net is very little.
Imports Microsoft.WindowsAPICodePack.Shell
Imports System.Text
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim RecycledFiles As ShellFile() = RecycleBin.MasterBin.Files
Dim sb As StringBuilder
' Loop through the deleted Items.
For Each Item As ShellFile In RecycledFiles
' Append the full name
sb.AppendLine(Item.Name)
' Append the DateDeleted.
sb.AppendLine(Item.Properties.GetProperty("DateDeleted").ValueAsObject.ToString)
MsgBox(sb.ToString)
sb.Clear()
Next Item
End Sub
End Class
However, I get a compiler error that RecycleBin is not declared. at
RecycleBin.MasterBin.Files
I am not too sure how to make this work. What is it that I am missing here? Is that a correct code ? Am I missing any Imports or any references?
I have already installed
nuget\Install-Package WindowsAPICodePack-Core
nuget\Install-Package WindowsAPICodePack-Shell
Note - I have already succeeded in accessing the RecycleBin using
SH.NameSpace(Shell32.ShellSpecialFolderConstants.ssfBITBUCKET)
I am specifically interested in that above piece of code. Thanks
To get the deletion date for items in the Recycle Bin, you don't need any extra libraries, you can use the Shell Objects for Scripting and Microsoft Visual Basic library (which I understand you already found in your last sentences) and the ExtendedProperty method.
Here is some code that dumps items in the recycle bin and their deletion date:
Sub Main()
Dim shell = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"))
Const ssfBITBUCKET As Integer = 10
Dim folder = shell.Namespace(ssfBITBUCKET)
For Each item In folder.Items
' dump some standard properties
Console.WriteLine(item.Path)
Console.WriteLine(item.ModifyDate)
' dump extended properties (note they are typed, here as a Date)
Dim dd As Date = item.ExtendedProperty("DateDeleted")
Console.WriteLine(dd)
' same but using the "canonical name"
' see https://learn.microsoft.com/en-us/windows/win32/api/propsys/nf-propsys-psgetpropertydescriptionbyname#remarks
Console.WriteLine(item.ExtendedProperty("System.Recycle.DateDeleted"))
Next
End Sub

Programmatically Add New Choice to Choice Column in SharePoint List

I'm working with a client and trying to make it so that when a button is pressed to open new Fiscal Year (FY) forms, it also adds that FY value as a choice option in a Document Library column. I also am trying to set the default to that new value.
I'm getting the error below.
Here's my current code. Is it simply a configuration issue? Or am I doing something n00by with my code?
Imports Microsoft.SharePoint
...
Partial Class _Default
Inherits System.Web.UI.Page
...
Protected Sub SaveNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SaveNew.Click
...
'Added 6/12/2019 - Testing new FY options in Document Upload Form
Using site As New SPSite("http://sptest/spsite/default.aspx")
Using web As SPWeb = site.OpenWeb()
Dim leadLst As SPList = web.Lists("Document Library")
Dim col As SPFieldChoice = CType(leadLst.Fields("Fiscal Year"), SPFieldChoice)
col.Choices.Add(FY.Text)
col.DefaultValue = FY.Text
col.update()
leadLst.update()
End Using
End Using
'End Added 6/12/2019
...
End Sub
When you are creting an object of SPSite, you need to pass the URL of Site Collection only not with .aspx page
Convert your SPSite object creation line from
Using site As New SPSite("http://sptest/spsite/default.aspx")
to
Using site As New SPSite("http://sptest/spsite/")
if spsite is your subsite and above code do not work then convert that line to
Using site As New SPSite("http://sptest/")
And then get SPWeb object for the spsite subsite
Let me know if this helps or not?

How to allow access to a folder?

Trying to write text from a text box to a file, keeping any text that is already in there, but this message comes up:
An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
Access to the path 'C:\Tickets.txt' is denied.
This is for a school assignment to create an IT ticketing software for a school.
What I have done so far:
Private Sub BtnComSubmit_Click(sender As Object, e As EventArgs) Handles BtnComSubmit.Click
My.Computer.FileSystem.WriteAllText("C:\Tickets.txt", TxtComList.Text, True)
End Sub
How could I give the necessary permission(s) to perform this action?
Change this:
My.Computer.FileSystem.WriteAllText("C:\Tickets.txt", TxtComList.Text, True)
To this:
Dim desktopPath As String = Environment.GetFolderPath( Environment.SpecialFolder.Desktop )
Dim filePath As String = System.IO.Path.Combine( desktopPath , "Tickets.txt" )
My.Computer.FileSystem.WriteAllText( filePath , TxtComList.Text, True )
BTW, I recommend avoiding the VB-specific My.Computer... stuff and using the System.IO API so you can graduate over to C# eventually with greater familiarity with .NET's APIs. Very few people stick with VB.NET for long.

Find username from email address in active directory vb.net

Sorry, i checked the link "Find username from Active Directory using email id" but that's for C# i can't figure that out how to do in Vb.net.
In my gridview when i select the row to get the email id and pass it to AD to find the user name but so far i can't figure that out what command will give that details in VB.net
Protected Sub grdValidate_RowUpdating(sender As Object, e As EventArgs)
Dim strEmail As String = grdValidate.SelectedRow.Cells(2).Text
Dim ctx As New PrincipalContext(ContextType.Domain)
' find a user
Dim user As UserPrincipal = UserPrincipal.FindByIdentity(ctx, strEmail)
End Sub
i saw this property "UserPrincipal.EmailAddress" but VS is not even recognize the command. Obviously i imported
Imports System.DirectoryServices
Imports System.DirectoryServices.AccountManagement
I am trying to find a command to pass the email and match the email id in AD and get the user information.
Thanks in Advance
You need to add .NET references to System.DirectoryServices and System.DirectoryServices.AccountManagement and then...
Using context As New System.DirectoryServices.AccountManagement.PrincipalContext(DirectoryServices.AccountManagement.ContextType.Domain, strDomainName)
Dim yourUser As System.DirectoryServices.AccountManagement.UserPrincipal = System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(context, strEmailAddress)
If yourUser IsNot Nothing Then
strFirstName = yourUser.GivenName
strLastName = yourUser.Surname
End If
End Using
MsgBox(strFirstName & " " & strLastName)
I've used fully qualified names for clarity, but you can tidy things up with Imports System.DirectoryServices.AccountManagement at the beginning of the module

Vb.net how can I set Search level as user input string

Intro... I've got a counter in my project that counts files in specified paths. Now all this depends on the users input as concerned would go into settings and set which extensions (tbExt1.text) that should be searched for as well as path (tbpath.text). The paths are listed in lbchannel1 listbox. Now this wont matter too much to my question, but I filled it in so my example below is more understandable.
Here comes the question: The users should be able to address if its going to count TopLevelOnly (FileIO.SearchOption.SearchTopLevelOnly) or TopAndSub (FileIO.SearchOption.SearchAllSubDirectories).
So I made a combobox that they can select from either of those two options. When they select one of them, FileIO.SearchOption.SearchTopLevelOnly or FileIO.SearchOption.SearchAllSubDirectories will become the text in a textbox tbTopOrSub1.text
That brings me to the next part. Instead of for example FileIO.SearchOption.SearchAllSubDirectories in my counter, I now added tbTopOrSub1.text as I hoped this would work the same way, but now be a user depended option. Have a look:
Dim TopOrSub1 As String
TopOrSub1 = tbTopOrSub1.Text
Dim fileTotal As Integer
For Each item As String In lbChannel1.Items
fileTotal += My.Computer.FileSystem.GetFiles(item.ToString, TopOrSub1, (tbExt1.Text)).Count
Next
I thought this would work like a charm, but it doesn't seem to work. I get this error The converting from string FileIO.SearchOption.SearchTopLev to type Integer is not valid (could be bad translation since the error was in Norwegian) and I notice how it sais TopLev. I suppose its too long? I can't figure out how to get around this.
First of all put Option Strict On for your VB project. This helps alot to avoid runtime errors.
The error occurs since you try to convert a string into an enumeration (=integer).
The good thing about comboboxes is that they have a DataSource property which can hold a collection of objects of any type. Additionally they have the following Properties:
DisplayMember: Name of a (public) property of the object set
in DataSource. The value of it will be displayed in the UI as "friendly" text.
ValueMember: Name of a property of the object set in DataSource. This value will not be shown in UI but you can accesss it in your code.
See my below exmaple how to use all these:
The object which holds the display text (Name) and the Value for your File Search Option:
Class FileSearchOption
Public Property Name As String
Public Property Value As FileIO.SearchOption
End Class
Fill your combobox and set its DataSource, DisplayMember and ValueMember:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim searchOptions As New List(Of FileSearchOption)
searchOptions.Add(New FileSearchOption() With {.Name = "TopLevelOnly", .Value = FileIO.SearchOption.SearchTopLevelOnly})
searchOptions.Add(New FileSearchOption() With {.Name = "TopAndSub", .Value = FileIO.SearchOption.SearchAllSubDirectories})
ComboBox1.DataSource = searchOptions
ComboBox1.DisplayMember = "Name"
ComboBox1.ValueMember = "Value"
End Sub
Handle the action when the user has chosen a search option. Remark that it is necessary to DirectCast the SelectedValue since it is of type Object.
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim fileTotal As Integer
For Each item As String In {"G:\"}
fileTotal += My.Computer.FileSystem.GetFiles(item.ToString, DirectCast(ComboBox1.SelectedValue, FileIO.SearchOption), (tbExt1.Text)).Count
Next
End Sub