C
C#17mo ago
MemeZ

Button that downloads a file from a link to a website

I need to click a button and it will download a file from a website link
144 Replies
Angius
Angius17mo ago
HttpClient
MemeZ
MemeZOP17mo ago
@ZZZZZZZZZZZZZZZZZZZZZZZZZ can you explain or help more
Angius
Angius17mo ago
For example https://stackoverflow.com/a/70418747
var httpClient = new HttpClient();
var responseStream = await httpClient.GetStreamAsync(requestUrl);
using var fileStream = new FileStream(localFilePath, FileMode.Create);
responseStream.CopyTo(fileStream);
var httpClient = new HttpClient();
var responseStream = await httpClient.GetStreamAsync(requestUrl);
using var fileStream = new FileStream(localFilePath, FileMode.Create);
responseStream.CopyTo(fileStream);
MemeZ
MemeZOP17mo ago
SO where would i input the URL to the download/file @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius17mo ago
Where.... it says requestUrl
MemeZ
MemeZOP17mo ago
just making sure sorry im sort of new to all this @ZZZZZZZZZZZZZZZZZZZZZZZZZ Also i'd put this in the button click right?
Angius
Angius17mo ago
Basically
MemeZ
MemeZOP17mo ago
i've got some errors
MemeZ
MemeZOP17mo ago
MemeZ
MemeZOP17mo ago
Angius
Angius17mo ago
The method needs to be async void not just void
MemeZ
MemeZOP17mo ago
oh got it
Angius
Angius17mo ago
And I guess you're using an old version of the language, so use a using block not statement And, well, all the variables that don't exist anywhere
MemeZ
MemeZOP17mo ago
like awating ect.
Angius
Angius17mo ago
?
MemeZ
MemeZOP17mo ago
wait mb im not sure i understand this part sorry
Angius
Angius17mo ago
Google is your friend in cases like those
MemeZ
MemeZOP17mo ago
oh alr and btw i put the link into where u said and
MemeZ
MemeZOP17mo ago
MemeZ
MemeZOP17mo ago
Angius
Angius17mo ago
Strings in C# need quotes around them The using is still a statement not a block And you have one more nonexistent variable
MemeZ
MemeZOP17mo ago
the file path? is the missing variable?
Angius
Angius17mo ago
Yes
MemeZ
MemeZOP17mo ago
does it go in quotes?
Angius
Angius17mo ago
If you want to use a literal path there and not a variable, yes As I already said...
MODiX
MODiX17mo ago
Angius
Strings in C# need quotes around them
React with ❌ to remove this embed.
MemeZ
MemeZOP17mo ago
if u wanted it to go to downloads it'd be c://Downloads right @ZZZZZZZZZZZZZZZZZZZZZZZZZ can you help i still dont know what to change using to @ZZZZZZZZZZZZZZZZZZZZZZZZZ another thing i dont the button is working anyway for some reason
Angius
Angius17mo ago
I guess Google fails somethimes, huh? using statement
using var foo = new SomeDisposable();
// code
using var foo = new SomeDisposable();
// code
using block
using (var foo = new SomeDisposable())
{
// code
}
using (var foo = new SomeDisposable())
{
// code
}
MemeZ
MemeZOP17mo ago
@ZZZZZZZZZZZZZZZZZZZZZZZZZ where do i put it now i have 44 errors
MemeZ
MemeZOP17mo ago
Angius
Angius17mo ago
Well not there
MemeZ
MemeZOP17mo ago
where lmao
Angius
Angius17mo ago
Instead of the using statement use the using block As I said before
MemeZ
MemeZOP17mo ago
yeah no ik that i mean like idk what to do tbh
Angius
Angius17mo ago
I just told you Instead of
using var foo = new SomeDisposable();
// code
using var foo = new SomeDisposable();
// code
make it
using (var foo = new SomeDisposable())
{
// code
}
using (var foo = new SomeDisposable())
{
// code
}
Or use a non-outdated version of the language
MemeZ
MemeZOP17mo ago
ik where do i put it @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius17mo ago
Where you have it...? If someone tells you to replace A with B that means you already have A So take out the A, and put B in its place I cannot be any more clear or I'll turn transparent
MemeZ
MemeZOP17mo ago
no bro what do i replace it with like what line
MemeZ
MemeZOP17mo ago
jcotton42
jcotton4217mo ago
What part of their directions are you confused by?
MODiX
MODiX17mo ago
Angius
Instead of
using var foo = new SomeDisposable();
// code
using var foo = new SomeDisposable();
// code
make it
using (var foo = new SomeDisposable())
{
// code
}
using (var foo = new SomeDisposable())
{
// code
}
React with ❌ to remove this embed.
MemeZ
MemeZOP17mo ago
Where do i put this code what line
Angius
Angius17mo ago
I'm out
MemeZ
MemeZOP17mo ago
the place i put it before you said was incorrect
Angius
Angius17mo ago
The brown fox
Jumped over
The lazy dog
The brown fox
Jumped over
The lazy dog
Please replace Jumped over with Crawled under
jcotton42
jcotton4217mo ago
My dude Look at the sample Z gave you Then look at your code The "instead of" is shaped like a particular line
MemeZ
MemeZOP17mo ago
homie its not in my code where tf u see user var foo at lmao bro
Angius
Angius17mo ago
Jesus It's an example You have something that looks similar
MemeZ
MemeZOP17mo ago
my boy then js tell me
jcotton42
jcotton4217mo ago
No Turn your brain back on
MemeZ
MemeZOP17mo ago
bro u cant yell at me for not knowing what to replace when nothing is similar to it
jcotton42
jcotton4217mo ago
Do you not see the using line already in your code?
MemeZ
MemeZOP17mo ago
the only error i see that i replaced it more errors bro its ONE line that says using which producing the error
jcotton42
jcotton4217mo ago
Yes And you were told to replace that with a different thing Z was very clear
MemeZ
MemeZOP17mo ago
ik and i did and i got more errors bro
artya
artya17mo ago
This is painful to read
jcotton42
jcotton4217mo ago
Then show them
MemeZ
MemeZOP17mo ago
so instead of "using var" i replace that with the bs he gave me
artya
artya17mo ago
he gave you psuedo code
jcotton42
jcotton4217mo ago
Not even pseudo It's very concrete
artya
artya17mo ago
True 😅
MemeZ
MemeZOP17mo ago
just fucking tell me what to replace it with so i can see it is it that hard bro
jcotton42
jcotton4217mo ago
We did
MemeZ
MemeZOP17mo ago
not a example that has 0 relevance or resembelence to what im dealing with
MODiX
MODiX17mo ago
Angius
Instead of
using var foo = new SomeDisposable();
// code
using var foo = new SomeDisposable();
// code
make it
using (var foo = new SomeDisposable())
{
// code
}
using (var foo = new SomeDisposable())
{
// code
}
React with ❌ to remove this embed.
Angius
Angius17mo ago
And I thought human brain evolved pattern recognition too well
jcotton42
jcotton4217mo ago
And if you already did that, show the new code and errors
MemeZ
MemeZOP17mo ago
in case ya noticed THAT example doesnt show a relevance
jcotton42
jcotton4217mo ago
We are not here to spoonfeed
MODiX
MODiX17mo ago
MemeZ
From MemeZ
React with ❌ to remove this embed.
jcotton42
jcotton4217mo ago
Is that current?
MemeZ
MemeZOP17mo ago
i've told u numerous times im new to this but when you tell me to replace something thats not there i cant annd yes
jcotton42
jcotton4217mo ago
MemeZ
MemeZOP17mo ago
BRO THATS WHAT I DID WHAT DONT U GET
jcotton42
jcotton4217mo ago
MemeZ
MemeZOP17mo ago
why would it give me more errors
jcotton42
jcotton4217mo ago
Then show the updated code already It should have a using block Exactly like Z told you to do
MemeZ
MemeZOP17mo ago
i replace this highlighted line with what he put
MemeZ
MemeZOP17mo ago
MODiX
MODiX17mo ago
Angius
Instead of
using var foo = new SomeDisposable();
// code
using var foo = new SomeDisposable();
// code
make it
using (var foo = new SomeDisposable())
{
// code
}
using (var foo = new SomeDisposable())
{
// code
}
React with ❌ to remove this embed.
jcotton42
jcotton4217mo ago
You are supposed to be using the second one
MemeZ
MemeZOP17mo ago
MemeZ
MemeZOP17mo ago
?
jcotton42
jcotton4217mo ago
<:picard_facepalm:616692703685509130> I'm done
Angius
Angius17mo ago
MemeZ
MemeZOP17mo ago
i dont know a single bit of C# bro
Angius
Angius17mo ago
Do you notice certain similarities? Adapt the examples given to your code
MemeZ
MemeZOP17mo ago
formats ect. yk what js how tf do i update @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius17mo ago
I told you Even made a pretty picture
MemeZ
MemeZOP17mo ago
js tell me how to update
Angius
Angius17mo ago
MemeZ
MemeZOP17mo ago
i dont wanna fix it js tell me how to update C# to 8 @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius17mo ago
Well, depends If it's a .NET Framework project, you might need to use an upgrade assistant
MemeZ
MemeZOP17mo ago
alright
Angius
Angius17mo ago
If it's a modern .NET project, just change the number in project properties
MemeZ
MemeZOP17mo ago
okay how do i check if its "modern"
Angius
Angius17mo ago
$newproject
MODiX
MODiX17mo ago
When creating a new project, prefer using .NET over .NET Framework, unless you have a very specific reason to be using .NET Framework. .NET Framework is now legacy code and only get security fix updates, it no longer gets new features and is not recommended. https://cdn.discordapp.com/attachments/569261465463160900/899381236617855016/unknown.png
Angius
Angius17mo ago
If you made a project in green it's good If you made a project in red it's bad
MemeZ
MemeZOP17mo ago
MemeZ
MemeZOP17mo ago
im guessin this is bad then
Angius
Angius17mo ago
Upgrade Assistant
MemeZ
MemeZOP17mo ago
alright how
Angius
Angius17mo ago
Or you could try editing the .csproj manually Or you could make a new project with a new version of .NET and copy the code over Whichever you prefer
MemeZ
MemeZOP17mo ago
would this most likley work
Angius
Angius17mo ago
Seeing how 4.8 is the newest of old Framework versions, it just might
MemeZ
MemeZOP17mo ago
okay can u show me how to edit it @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius17mo ago
You'll have to edit TargetFramework to, say, net7.0 and LangVersion to, say, 11
MemeZ
MemeZOP17mo ago
where can i do that
Angius
Angius17mo ago
Inside of the .csproj file...? And just to get ahead of you, no, the file is not literally named .csproj It's YourProjectName.csproj And no, it's not literal YourProjectName.csproj But rather, well, your project's name With the extension .csproj Open it with any text editor, Notepad, Notepad++, whatever Edit Save
MemeZ
MemeZOP17mo ago
ik im in i cant find the lanf v lang version * @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius17mo ago
What does your .csproj file look like?
MemeZ
MemeZOP17mo ago
Angius
Angius17mo ago
Eh, it might work Not entirely sure, to be honest It's been ages since I worked with legacy Framework last, and I never had to port anything to modern .NET either
MemeZ
MemeZOP17mo ago
so what abt the lang version? is that all i needed to do
Angius
Angius17mo ago
Lang version might not be needed
MemeZ
MemeZOP17mo ago
alright
Angius
Angius17mo ago
Or you can try just adding it there manually Right now, see if it works
MemeZ
MemeZOP17mo ago
alright
MemeZ
MemeZOP17mo ago
MemeZ
MemeZOP17mo ago
MemeZ
MemeZOP17mo ago
@ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius17mo ago
¯\_(ツ)_/¯ then You'll have to find someone more well-versed Or use the upgrade assistant maybe
MemeZ
MemeZOP17mo ago
alrigiht
Angius
Angius17mo ago
Never used it myself, but people say it does help
MemeZ
MemeZOP17mo ago
instead of downloading the file straight on can i make a website redirect?
Angius
Angius17mo ago
What do you mean?
MemeZ
MemeZOP17mo ago
like u click the button and it brings you to a website
Angius
Angius17mo ago
Sure
MemeZ
MemeZOP17mo ago
alright how exactly would that work
Angius
Angius17mo ago
Process.Start("http://google.com") should be all you need
MemeZ
MemeZOP17mo ago
oh alr let me see
Angius
Angius17mo ago
It's in the System.Diagnostics namespace
MemeZ
MemeZOP17mo ago
do i keep the async? on the button the button didn't do anything
Angius
Angius17mo ago
No need for async if you're not awaiting inside
MemeZ
MemeZOP17mo ago
thought so but it still didn't work no error just nothing happens @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius17mo ago
Odd, it should work
MemeZ
MemeZOP17mo ago
niether did message boxes
Angius
Angius17mo ago
Ah
Process.Start(new ProcessStartInfo() { FileName = "https://google.com", UseShellExecute = true });
Process.Start(new ProcessStartInfo() { FileName = "https://google.com", UseShellExecute = true });
maybe?
MemeZ
MemeZOP17mo ago
literally nothing could it be the linking to the button maybe? the settings @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius17mo ago
Does anything happen when you click the button? Would be best if you were to debug it See if breakpoints are being hit
MemeZ
MemeZOP17mo ago
no absolutley nothin what could it be @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius17mo ago
No idea
MemeZ
MemeZOP17mo ago
damn
Want results from more Discord servers?
Add your server