SparkyCracked
SparkyCracked
CC#
Created by SparkyCracked on 5/13/2024 in #help
✅ UI winforms combobox issue
No description
10 replies
CC#
Created by SparkyCracked on 4/5/2024 in #help
✅ Guidance needed for encryption
Good day. I want to dive into creating my own encryption method/class. I want it to be similar to what the big companies do as I want to present it forward to the company I work at. They don't have their own encryption method. I did some research and found the Rijndael algorithm and found it "a worthy" method. My main reason for asking for help is just to ask if you know any recourses or any existing open source methods that I can use to just guide me in completing this project. If you know any other methods that are secure and also really well sourced please let me know. I am doing this project to further my knowledge with C# and actually have an impressive project to showcase if the company decides to not use it.
20 replies
CC#
Created by SparkyCracked on 4/3/2024 in #help
✅ BackgroundWorker getting progress
I have a winform applications and with this I have put a ProgressBar on it. I was manually changing the progress inside functions using progressBar.Value = <value> but now that I run my functions in the background using BackgroundWorker, changing that progress is a little harder than I thought. If I am not mistaken the code below is defined as a 'Delegate Invocation' and I use it to run the function I would like to track progress of:
c#
public void ModifyTQWorker(object sender, DoWorkEventArgs e)
{
try
{
object[] args = e.Argument as object[];
if (args != null && args.Length == 4)
{
ClientContext context = args[0] as ClientContext;
Microsoft.SharePoint.Client.List listObj = args[1] as Microsoft.SharePoint.Client.List;
string TQNumber = args[2] as string;
User Raisedby = args[3] as User;

if (context != null && listObj != null && TQNumber != null && Raisedby != null)
{
(sender as BackgroundWorker).ReportProgress(10);
ModifyTQ(context, listObj, TQNumber, Raisedby);
}
else
{
MessageBox.Show("One of the parameters was not given for the ModifyTQWorker.", "Error");
}
}
}catch(Exception ex)
{
MessageBox.Show($"There was an issue modifying the current TQ.\n{ex.Message}", "Error");
}
}
c#
public void ModifyTQWorker(object sender, DoWorkEventArgs e)
{
try
{
object[] args = e.Argument as object[];
if (args != null && args.Length == 4)
{
ClientContext context = args[0] as ClientContext;
Microsoft.SharePoint.Client.List listObj = args[1] as Microsoft.SharePoint.Client.List;
string TQNumber = args[2] as string;
User Raisedby = args[3] as User;

if (context != null && listObj != null && TQNumber != null && Raisedby != null)
{
(sender as BackgroundWorker).ReportProgress(10);
ModifyTQ(context, listObj, TQNumber, Raisedby);
}
else
{
MessageBox.Show("One of the parameters was not given for the ModifyTQWorker.", "Error");
}
}
}catch(Exception ex)
{
MessageBox.Show($"There was an issue modifying the current TQ.\n{ex.Message}", "Error");
}
}
How can I give progress better?
17 replies
CC#
Created by SparkyCracked on 3/19/2024 in #help
Casting object to enum class
So I have:
enum AClass { double, int, string }
enum AClass { double, int, string }
And I wanna case my object to that class:
obj a = 0;
(AClass)a;
obj a = 0;
(AClass)a;
There is a reflector to determine what variable type it is but it kinda does this on runtime/compile. I wanna know if there is a way to cast this without wrapping it
114 replies
CC#
Created by SparkyCracked on 3/18/2024 in #help
✅ System threading tasks
No description
20 replies
CC#
Created by SparkyCracked on 1/28/2024 in #help
✅ Winforms: open two forms at the same time
Good day everyone. So I have an issue (duhh, thats why I am here xD). I am trying to get a screenshot of the users image...I am using two forms to achieve this, one to show the image and another to screenshot. When I try open the first form AspectRatioForm and then the second SelectArea. It throws the issue below:
System.ArgumentException: 'Parameter is not valid.'
System.ArgumentException: 'Parameter is not valid.'
This is the code I wrote:
c#
public void openImageScreenshot(string imageLocationPath, PictureBox pictureBox)
{
SelectArea area = new SelectArea(this);

area.BringToFront();
area.Activate();

using (Image img = Image.FromFile(imageLocationPath))
{
AspectRatioForm aspectRatioForm = new AspectRatioForm(img);
aspectRatioForm.Show();
}
this.Hide();
area.ShowDialog();
// After showing and hiding the SelectArea form, you can access the file path:
string imagePathScreenshot = area.GetScreenshotFilePath();
pictureBox.ImageLocation = imagePathScreenshot;
this.Show();
}
c#
public void openImageScreenshot(string imageLocationPath, PictureBox pictureBox)
{
SelectArea area = new SelectArea(this);

area.BringToFront();
area.Activate();

using (Image img = Image.FromFile(imageLocationPath))
{
AspectRatioForm aspectRatioForm = new AspectRatioForm(img);
aspectRatioForm.Show();
}
this.Hide();
area.ShowDialog();
// After showing and hiding the SelectArea form, you can access the file path:
string imagePathScreenshot = area.GetScreenshotFilePath();
pictureBox.ImageLocation = imagePathScreenshot;
this.Show();
}
Now I don't know why this is happening because if I call them separately in terms of their own functions using ShowDialog they both show one by one (once one form closes the other will show).
7 replies
CC#
Created by SparkyCracked on 1/11/2024 in #help
Capturing multiple displays scaling information
No description
31 replies
CC#
Created by SparkyCracked on 1/5/2024 in #help
GUI Design / Thoughts on user experience
No description
5 replies
CC#
Created by SparkyCracked on 1/2/2024 in #help
Windows Form App - SharePoint Image Upload
Hello everyone, I'm currently working on a Windows Form application using C# and have encountered an issue with uploading images to SharePoint. The objective is to allow users to upload images through the Windows Form, and I want these images to be reflected in a SharePoint table. Here's a quick overview of my process: 1. Users upload images through the Windows Form app. 2. The app uploads images to SharePoint's siteassets. 3. The corresponding SharePoint table gets updated with image information. The challenge I'm facing is that while the images successfully upload to SharePoint's siteassets, they don't appear in the SharePoint table. Bellow is a snippet of code:
while (FileExistsInFolder(context, documentsLibrary, newFileName))
{
fileCount++;
newFileName = $"{coreFileName} ({fileCount}){fileExtension}";
}

// uploading the file
using (FileStream fs = System.IO.File.OpenRead(filePath))
{
FileCreationInformation flciNewFile = new FileCreationInformation();

flciNewFile.ContentStream = fs;
flciNewFile.Url = newFileName;
flciNewFile.Overwrite = false;
Microsoft.SharePoint.Client.File uploadFile = documentsLibrary.Files.Add(flciNewFile);
context.Load(uploadFile);
context.ExecuteQuery();
}
image_url = $"https://<website>.sharepoint.com/{context.Web.ServerRelativeUrl}{siteAssetsUrl}/{newFileName}";
image_url = image_url.Replace(" ", "%20");
Console.WriteLine("Here is the url:\n" + image_url);
MessageBox.Show("This is the url (check console to copy):\n" + image_url);
}
else
{
image_url = string.Empty;
}

//Add new TQ to Register
ListItemCreationInformation newTQInfo = new ListItemCreationInformation();
ListItem newTQ = listObj.AddItem(newTQInfo);
newTQ["RaisedBy"] = Raisedby;
newTQ["Subject_x002f_Description"] = TQSubject.Text;
newTQ["ApplicableDrawing_x002f_ModelNum"] = TQDwgNo.Text;
newTQ["Area_x002f_Equipment"] = TQAreaEquip.Text;
newTQ["ParaMaticSuggestion"] = TQPMRemark.Text;
newTQ["DateRaised"] = dateTimePicker1.Value.ToString();
newTQ["ECRNumber"] = newTQNumber;
newTQ["ContractNumber"] = SelectedProjectItem;

// Attempting to update the attatchement folder
string fileName = "workTester.png";
byte[] fileBytes = System.IO.File.ReadAllBytes(imagePath);
newTQ["OverallImage1"] = fileBytes;
while (FileExistsInFolder(context, documentsLibrary, newFileName))
{
fileCount++;
newFileName = $"{coreFileName} ({fileCount}){fileExtension}";
}

// uploading the file
using (FileStream fs = System.IO.File.OpenRead(filePath))
{
FileCreationInformation flciNewFile = new FileCreationInformation();

flciNewFile.ContentStream = fs;
flciNewFile.Url = newFileName;
flciNewFile.Overwrite = false;
Microsoft.SharePoint.Client.File uploadFile = documentsLibrary.Files.Add(flciNewFile);
context.Load(uploadFile);
context.ExecuteQuery();
}
image_url = $"https://<website>.sharepoint.com/{context.Web.ServerRelativeUrl}{siteAssetsUrl}/{newFileName}";
image_url = image_url.Replace(" ", "%20");
Console.WriteLine("Here is the url:\n" + image_url);
MessageBox.Show("This is the url (check console to copy):\n" + image_url);
}
else
{
image_url = string.Empty;
}

//Add new TQ to Register
ListItemCreationInformation newTQInfo = new ListItemCreationInformation();
ListItem newTQ = listObj.AddItem(newTQInfo);
newTQ["RaisedBy"] = Raisedby;
newTQ["Subject_x002f_Description"] = TQSubject.Text;
newTQ["ApplicableDrawing_x002f_ModelNum"] = TQDwgNo.Text;
newTQ["Area_x002f_Equipment"] = TQAreaEquip.Text;
newTQ["ParaMaticSuggestion"] = TQPMRemark.Text;
newTQ["DateRaised"] = dateTimePicker1.Value.ToString();
newTQ["ECRNumber"] = newTQNumber;
newTQ["ContractNumber"] = SelectedProjectItem;

// Attempting to update the attatchement folder
string fileName = "workTester.png";
byte[] fileBytes = System.IO.File.ReadAllBytes(imagePath);
newTQ["OverallImage1"] = fileBytes;
4 replies