C
C#2y 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
Angius2y ago
HttpClient
MemeZ
MemeZOP2y ago
@ZZZZZZZZZZZZZZZZZZZZZZZZZ can you explain or help more
Angius
Angius2y 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
MemeZOP2y ago
SO where would i input the URL to the download/file @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius2y ago
Where.... it says requestUrl
MemeZ
MemeZOP2y ago
just making sure sorry im sort of new to all this @ZZZZZZZZZZZZZZZZZZZZZZZZZ Also i'd put this in the button click right?
Angius
Angius2y ago
Basically
MemeZ
MemeZOP2y ago
i've got some errors
MemeZ
MemeZOP2y ago
MemeZ
MemeZOP2y ago
Angius
Angius2y ago
The method needs to be async void not just void
MemeZ
MemeZOP2y ago
oh got it
Angius
Angius2y 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
MemeZOP2y ago
like awating ect.
Angius
Angius2y ago
?
MemeZ
MemeZOP2y ago
wait mb im not sure i understand this part sorry
Angius
Angius2y ago
Google is your friend in cases like those
MemeZ
MemeZOP2y ago
oh alr and btw i put the link into where u said and
MemeZ
MemeZOP2y ago
MemeZ
MemeZOP2y ago
Angius
Angius2y 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
MemeZOP2y ago
the file path? is the missing variable?
Angius
Angius2y ago
Yes
MemeZ
MemeZOP2y ago
does it go in quotes?
Angius
Angius2y ago
If you want to use a literal path there and not a variable, yes As I already said...
MODiX
MODiX2y ago
Angius
Strings in C# need quotes around them
React with ❌ to remove this embed.
MemeZ
MemeZOP2y 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
Angius2y 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
MemeZOP2y ago
@ZZZZZZZZZZZZZZZZZZZZZZZZZ where do i put it now i have 44 errors
MemeZ
MemeZOP2y ago
Angius
Angius2y ago
Well not there
MemeZ
MemeZOP2y ago
where lmao
Angius
Angius2y ago
Instead of the using statement use the using block As I said before
MemeZ
MemeZOP2y ago
yeah no ik that i mean like idk what to do tbh
Angius
Angius2y 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
MemeZOP2y ago
ik where do i put it @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius2y 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
MemeZOP2y ago
no bro what do i replace it with like what line
MemeZ
MemeZOP2y ago
jcotton42
jcotton422y ago
What part of their directions are you confused by?
MODiX
MODiX2y 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
MemeZOP2y ago
Where do i put this code what line
Angius
Angius2y ago
I'm out
MemeZ
MemeZOP2y ago
the place i put it before you said was incorrect
Angius
Angius2y 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
jcotton422y 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
MemeZOP2y ago
homie its not in my code where tf u see user var foo at lmao bro
Angius
Angius2y ago
Jesus It's an example You have something that looks similar
MemeZ
MemeZOP2y ago
my boy then js tell me
jcotton42
jcotton422y ago
No Turn your brain back on
MemeZ
MemeZOP2y ago
bro u cant yell at me for not knowing what to replace when nothing is similar to it
jcotton42
jcotton422y ago
Do you not see the using line already in your code?
MemeZ
MemeZOP2y ago
the only error i see that i replaced it more errors bro its ONE line that says using which producing the error
jcotton42
jcotton422y ago
Yes And you were told to replace that with a different thing Z was very clear
MemeZ
MemeZOP2y ago
ik and i did and i got more errors bro
artya
artya2y ago
This is painful to read
jcotton42
jcotton422y ago
Then show them
MemeZ
MemeZOP2y ago
so instead of "using var" i replace that with the bs he gave me
artya
artya2y ago
he gave you psuedo code
jcotton42
jcotton422y ago
Not even pseudo It's very concrete
artya
artya2y ago
True 😅
MemeZ
MemeZOP2y ago
just fucking tell me what to replace it with so i can see it is it that hard bro
jcotton42
jcotton422y ago
We did
MemeZ
MemeZOP2y ago
not a example that has 0 relevance or resembelence to what im dealing with
MODiX
MODiX2y 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
Angius2y ago
And I thought human brain evolved pattern recognition too well
jcotton42
jcotton422y ago
And if you already did that, show the new code and errors
MemeZ
MemeZOP2y ago
in case ya noticed THAT example doesnt show a relevance
jcotton42
jcotton422y ago
We are not here to spoonfeed
MODiX
MODiX2y ago
MemeZ
From MemeZ
React with ❌ to remove this embed.
jcotton42
jcotton422y ago
Is that current?
MemeZ
MemeZOP2y 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
jcotton422y ago
MemeZ
MemeZOP2y ago
BRO THATS WHAT I DID WHAT DONT U GET
jcotton42
jcotton422y ago
MemeZ
MemeZOP2y ago
why would it give me more errors
jcotton42
jcotton422y ago
Then show the updated code already It should have a using block Exactly like Z told you to do
MemeZ
MemeZOP2y ago
i replace this highlighted line with what he put
MemeZ
MemeZOP2y ago
MODiX
MODiX2y 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
jcotton422y ago
You are supposed to be using the second one
MemeZ
MemeZOP2y ago
MemeZ
MemeZOP2y ago
?
jcotton42
jcotton422y ago
<:picard_facepalm:616692703685509130> I'm done
Angius
Angius2y ago
MemeZ
MemeZOP2y ago
i dont know a single bit of C# bro
Angius
Angius2y ago
Do you notice certain similarities? Adapt the examples given to your code
MemeZ
MemeZOP2y ago
formats ect. yk what js how tf do i update @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius2y ago
I told you Even made a pretty picture
MemeZ
MemeZOP2y ago
js tell me how to update
Angius
Angius2y ago
MemeZ
MemeZOP2y ago
i dont wanna fix it js tell me how to update C# to 8 @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius2y ago
Well, depends If it's a .NET Framework project, you might need to use an upgrade assistant
MemeZ
MemeZOP2y ago
alright
Angius
Angius2y ago
If it's a modern .NET project, just change the number in project properties
MemeZ
MemeZOP2y ago
okay how do i check if its "modern"
Angius
Angius2y ago
$newproject
MODiX
MODiX2y 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
Angius2y ago
If you made a project in green it's good If you made a project in red it's bad
MemeZ
MemeZOP2y ago
MemeZ
MemeZOP2y ago
im guessin this is bad then
Angius
Angius2y ago
Upgrade Assistant
MemeZ
MemeZOP2y ago
alright how
Angius
Angius2y 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
MemeZOP2y ago
would this most likley work
Angius
Angius2y ago
Seeing how 4.8 is the newest of old Framework versions, it just might
MemeZ
MemeZOP2y ago
okay can u show me how to edit it @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius2y ago
You'll have to edit TargetFramework to, say, net7.0 and LangVersion to, say, 11
MemeZ
MemeZOP2y ago
where can i do that
Angius
Angius2y 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
MemeZOP2y ago
ik im in i cant find the lanf v lang version * @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius2y ago
What does your .csproj file look like?
MemeZ
MemeZOP2y ago
Angius
Angius2y 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
MemeZOP2y ago
so what abt the lang version? is that all i needed to do
Angius
Angius2y ago
Lang version might not be needed
MemeZ
MemeZOP2y ago
alright
Angius
Angius2y ago
Or you can try just adding it there manually Right now, see if it works
MemeZ
MemeZOP2y ago
alright
MemeZ
MemeZOP2y ago
MemeZ
MemeZOP2y ago
MemeZ
MemeZOP2y ago
@ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius2y ago
¯\_(ツ)_/¯ then You'll have to find someone more well-versed Or use the upgrade assistant maybe
MemeZ
MemeZOP2y ago
alrigiht
Angius
Angius2y ago
Never used it myself, but people say it does help
MemeZ
MemeZOP2y ago
instead of downloading the file straight on can i make a website redirect?
Angius
Angius2y ago
What do you mean?
MemeZ
MemeZOP2y ago
like u click the button and it brings you to a website
Angius
Angius2y ago
Sure
MemeZ
MemeZOP2y ago
alright how exactly would that work
Angius
Angius2y ago
Process.Start("http://google.com") should be all you need
MemeZ
MemeZOP2y ago
oh alr let me see
Angius
Angius2y ago
It's in the System.Diagnostics namespace
MemeZ
MemeZOP2y ago
do i keep the async? on the button the button didn't do anything
Angius
Angius2y ago
No need for async if you're not awaiting inside
MemeZ
MemeZOP2y ago
thought so but it still didn't work no error just nothing happens @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius2y ago
Odd, it should work
MemeZ
MemeZOP2y ago
niether did message boxes
Angius
Angius2y ago
Ah
Process.Start(new ProcessStartInfo() { FileName = "https://google.com", UseShellExecute = true });
Process.Start(new ProcessStartInfo() { FileName = "https://google.com", UseShellExecute = true });
maybe?
MemeZ
MemeZOP2y ago
literally nothing could it be the linking to the button maybe? the settings @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius2y 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
MemeZOP2y ago
no absolutley nothin what could it be @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius2y ago
No idea
MemeZ
MemeZOP2y ago
damn

Did you find this page helpful?