Add-Type -AssemblyName System.Windows.Forms Import-Module PnP.PowerShell # Import our components . "$PSScriptRoot\SharePointFunctions.ps1" . "$PSScriptRoot\EventHandlers.ps1" # Create main form $form = New-Object System.Windows.Forms.Form $form.Text = "SharePoint XLS Converter" $form.Size = New-Object System.Drawing.Size(600,500) # Add controls $lblConfig = New-Object System.Windows.Forms.Label $lblConfig.Text = "SharePoint Configuration:" $lblConfig.Location = New-Object System.Drawing.Point(20,20) $lblConfig.Size = New-Object System.Drawing.Size(200,20) $form.Controls.Add($lblConfig) $txtSiteUrl = New-Object System.Windows.Forms.TextBox $txtSiteUrl.Location = New-Object System.Drawing.Point(20,40) $txtSiteUrl.Size = New-Object System.Drawing.Size(200,20) $txtSiteUrl.PlaceholderText = "Site URL" $txtProdLib = New-Object System.Windows.Forms.TextBox $txtProdLib.Location = New-Object System.Drawing.Point(20,70) $txtProdLib.Size = New-Object System.Drawing.Size(200,20) $txtProdLib.PlaceholderText = "Production Library" $txtTempLib = New-Object System.Windows.Forms.TextBox $txtTempLib.Location = New-Object System.Drawing.Point(20,100) $txtTempLib.Size = New-Object System.Drawing.Size(200,20) $txtTempLib.PlaceholderText = "Temp Library" $txtFolder = New-Object System.Windows.Forms.TextBox $txtFolder.Location = New-Object System.Drawing.Point(20,130) $txtFolder.Size = New-Object System.Drawing.Size(200,20) $txtFolder.PlaceholderText = "Folder Path (optional)" $btnBrowse = New-Object System.Windows.Forms.Button $btnBrowse.Location = New-Object System.Drawing.Point(230,130) $btnBrowse.Size = New-Object System.Drawing.Size(80,20) $btnBrowse.Text = "Browse" $btnList = New-Object System.Windows.Forms.Button $btnList.Location = New-Object System.Drawing.Point(20,170) $btnList.Size = New-Object System.Drawing.Size(120,30) $btnList.Text = "List XLS Files" $form.Controls.Add($btnList) $btnConvert = New-Object System.Windows.Forms.Button $btnConvert.Location = New-Object System.Drawing.Point(160,170) $btnConvert.Size = New-Object System.Drawing.Size(120,30) $btnConvert.Text = "Convert to XLSX" $form.Controls.Add($btnConvert) $btnMove = New-Object System.Windows.Forms.Button $btnMove.Location = New-Object System.Drawing.Point(300,170) $btnMove.Size = New-Object System.Drawing.Size(120,30) $btnMove.Text = "Move Files" $form.Controls.Add($btnMove) $txtStatus = New-Object System.Windows.Forms.TextBox $txtStatus.Location = New-Object System.Drawing.Point(20,210) $txtStatus.Size = New-Object System.Drawing.Size(540,240) $txtStatus.Multiline = $true $txtStatus.ScrollBars = "Vertical" $form.Controls.Add($txtStatus) # Add Save Config button $btnSaveConfig = New-Object System.Windows.Forms.Button $btnSaveConfig.Location = New-Object System.Drawing.Point(230,40) $btnSaveConfig.Size = New-Object System.Drawing.Size(80,20) $btnSaveConfig.Text = "Save Config" $btnSaveConfig.Add_Click({ Save-Config -SiteUrl $txtSiteUrl.Text ` -ProductionLibrary $txtProdLib.Text ` -TempLibrary $txtTempLib.Text }) $form.Controls.AddRange(@( $txtSiteUrl, $txtProdLib, $txtTempLib, $txtFolder, $btnBrowse, $btnSaveConfig )) # Load configuration if (-not (Load-Config)) { [System.Windows.Forms.MessageBox]::Show("Configuration missing! Please enter settings.") } else { $txtSiteUrl.Text = $config.SiteUrl $txtProdLib.Text = $config.ProductionLibrary $txtTempLib.Text = $config.TempLibrary } # Attach event handlers $btnList.Add_Click({ List-XlsFiles }) $btnConvert.Add_Click({ Convert-Files }) $btnMove.Add_Click({ Move-Files }) $btnBrowse.Add_Click({ try { if (-not (Connect-SharePoint)) { [System.Windows.Forms.MessageBox]::Show("Please configure and connect to SharePoint first!") return } $selectedFolder = Get-FolderBrowser if ($selectedFolder) { $webUrl = (Get-PnPWeb).ServerRelativeUrl $relativePath = $selectedFolder.ServerRelativeUrl -replace [regex]::Escape($webUrl), "" $script:txtFolder.Text = $relativePath.Trim('/') } } catch { $script:txtStatus.Text += "Folder browse error: $_`n" } }) # Show form $form.Add_Shown({$form.Activate()}) [void]$form.ShowDialog()