C
C#12mo 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
Angius12mo ago
HttpClient
MemeZ
MemeZ12mo ago
@ZZZZZZZZZZZZZZZZZZZZZZZZZ can you explain or help more
Angius
Angius12mo 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
MemeZ12mo ago
SO where would i input the URL to the download/file @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius12mo ago
Where.... it says requestUrl
MemeZ
MemeZ12mo ago
just making sure sorry im sort of new to all this @ZZZZZZZZZZZZZZZZZZZZZZZZZ Also i'd put this in the button click right?
Angius
Angius12mo ago
Basically
MemeZ
MemeZ12mo ago
i've got some errors
MemeZ
MemeZ12mo ago
MemeZ
MemeZ12mo ago
Angius
Angius12mo ago
The method needs to be async void not just void
MemeZ
MemeZ12mo ago
oh got it
Angius
Angius12mo 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
MemeZ12mo ago
like awating ect.
Angius
Angius12mo ago
?
MemeZ
MemeZ12mo ago
wait mb im not sure i understand this part sorry
Angius
Angius12mo ago
Google is your friend in cases like those
MemeZ
MemeZ12mo ago
oh alr and btw i put the link into where u said and
MemeZ
MemeZ12mo ago
MemeZ
MemeZ12mo ago
Angius
Angius12mo 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
MemeZ12mo ago
the file path? is the missing variable?
Angius
Angius12mo ago
Yes
MemeZ
MemeZ12mo ago
does it go in quotes?
Angius
Angius12mo ago
If you want to use a literal path there and not a variable, yes As I already said...
MODiX
MODiX12mo ago
Angius
Strings in C# need quotes around them
React with ❌ to remove this embed.
MemeZ
MemeZ12mo 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
Angius12mo 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
MemeZ12mo ago
@ZZZZZZZZZZZZZZZZZZZZZZZZZ where do i put it now i have 44 errors
MemeZ
MemeZ12mo ago
Angius
Angius12mo ago
Well not there
MemeZ
MemeZ12mo ago
where lmao
Angius
Angius12mo ago
Instead of the using statement use the using block As I said before
MemeZ
MemeZ12mo ago
yeah no ik that i mean like idk what to do tbh
Angius
Angius12mo 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
MemeZ12mo ago
ik where do i put it @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius12mo 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
MemeZ12mo ago
no bro what do i replace it with like what line
MemeZ
MemeZ12mo ago
jcotton42
jcotton4212mo ago
What part of their directions are you confused by?
MODiX
MODiX12mo 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
MemeZ12mo ago
Where do i put this code what line
Angius
Angius12mo ago
I'm out
MemeZ
MemeZ12mo ago
the place i put it before you said was incorrect
Angius
Angius12mo 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
jcotton4212mo 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
MemeZ12mo ago
homie its not in my code where tf u see user var foo at lmao bro
Angius
Angius12mo ago
Jesus It's an example You have something that looks similar
MemeZ
MemeZ12mo ago
my boy then js tell me
jcotton42
jcotton4212mo ago
No Turn your brain back on
MemeZ
MemeZ12mo ago
bro u cant yell at me for not knowing what to replace when nothing is similar to it
jcotton42
jcotton4212mo ago
Do you not see the using line already in your code?
MemeZ
MemeZ12mo ago
the only error i see that i replaced it more errors bro its ONE line that says using which producing the error
jcotton42
jcotton4212mo ago
Yes And you were told to replace that with a different thing Z was very clear
MemeZ
MemeZ12mo ago
ik and i did and i got more errors bro
artya
artya12mo ago
This is painful to read
jcotton42
jcotton4212mo ago
Then show them
MemeZ
MemeZ12mo ago
so instead of "using var" i replace that with the bs he gave me
artya
artya12mo ago
he gave you psuedo code
jcotton42
jcotton4212mo ago
Not even pseudo It's very concrete
artya
artya12mo ago
True 😅
MemeZ
MemeZ12mo ago
just fucking tell me what to replace it with so i can see it is it that hard bro
jcotton42
jcotton4212mo ago
We did
MemeZ
MemeZ12mo ago
not a example that has 0 relevance or resembelence to what im dealing with
MODiX
MODiX12mo 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
Angius12mo ago
And I thought human brain evolved pattern recognition too well
jcotton42
jcotton4212mo ago
And if you already did that, show the new code and errors
MemeZ
MemeZ12mo ago
in case ya noticed THAT example doesnt show a relevance
jcotton42
jcotton4212mo ago
We are not here to spoonfeed
MODiX
MODiX12mo ago
MemeZ
From MemeZ
React with ❌ to remove this embed.
jcotton42
jcotton4212mo ago
Is that current?
MemeZ
MemeZ12mo 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
jcotton4212mo ago
MemeZ
MemeZ12mo ago
BRO THATS WHAT I DID WHAT DONT U GET
jcotton42
jcotton4212mo ago
MemeZ
MemeZ12mo ago
why would it give me more errors
jcotton42
jcotton4212mo ago
Then show the updated code already It should have a using block Exactly like Z told you to do
MemeZ
MemeZ12mo ago
i replace this highlighted line with what he put
MemeZ
MemeZ12mo ago
MODiX
MODiX12mo 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
jcotton4212mo ago
You are supposed to be using the second one
MemeZ
MemeZ12mo ago
MemeZ
MemeZ12mo ago
?
jcotton42
jcotton4212mo ago
<:picard_facepalm:616692703685509130> I'm done
Angius
Angius12mo ago
MemeZ
MemeZ12mo ago
i dont know a single bit of C# bro
Angius
Angius12mo ago
Do you notice certain similarities? Adapt the examples given to your code
MemeZ
MemeZ12mo ago
formats ect. yk what js how tf do i update @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius12mo ago
I told you Even made a pretty picture
MemeZ
MemeZ12mo ago
js tell me how to update
Angius
Angius12mo ago
MemeZ
MemeZ12mo ago
i dont wanna fix it js tell me how to update C# to 8 @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius12mo ago
Well, depends If it's a .NET Framework project, you might need to use an upgrade assistant
MemeZ
MemeZ12mo ago
alright
Angius
Angius12mo ago
If it's a modern .NET project, just change the number in project properties
MemeZ
MemeZ12mo ago
okay how do i check if its "modern"
Angius
Angius12mo ago
$newproject
MODiX
MODiX12mo 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
Angius12mo ago
If you made a project in green it's good If you made a project in red it's bad
MemeZ
MemeZ12mo ago
MemeZ
MemeZ12mo ago
im guessin this is bad then
Angius
Angius12mo ago
Upgrade Assistant
MemeZ
MemeZ12mo ago
alright how
Angius
Angius12mo 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
MemeZ12mo ago
would this most likley work
Angius
Angius12mo ago
Seeing how 4.8 is the newest of old Framework versions, it just might
MemeZ
MemeZ12mo ago
okay can u show me how to edit it @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius12mo ago
You'll have to edit TargetFramework to, say, net7.0 and LangVersion to, say, 11
MemeZ
MemeZ12mo ago
where can i do that
Angius
Angius12mo 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
MemeZ12mo ago
ik im in i cant find the lanf v lang version * @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius12mo ago
What does your .csproj file look like?
MemeZ
MemeZ12mo ago
Angius
Angius12mo 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
MemeZ12mo ago
so what abt the lang version? is that all i needed to do
Angius
Angius12mo ago
Lang version might not be needed
MemeZ
MemeZ12mo ago
alright
Angius
Angius12mo ago
Or you can try just adding it there manually Right now, see if it works
MemeZ
MemeZ12mo ago
alright
MemeZ
MemeZ12mo ago
MemeZ
MemeZ12mo ago
MemeZ
MemeZ12mo ago
@ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius12mo ago
¯\_(ツ)_/¯ then You'll have to find someone more well-versed Or use the upgrade assistant maybe
MemeZ
MemeZ12mo ago
alrigiht
Angius
Angius12mo ago
Never used it myself, but people say it does help
MemeZ
MemeZ12mo ago
instead of downloading the file straight on can i make a website redirect?
Angius
Angius12mo ago
What do you mean?
MemeZ
MemeZ12mo ago
like u click the button and it brings you to a website
Angius
Angius12mo ago
Sure
MemeZ
MemeZ12mo ago
alright how exactly would that work
Angius
Angius12mo ago
Process.Start("http://google.com") should be all you need
MemeZ
MemeZ12mo ago
oh alr let me see
Angius
Angius12mo ago
It's in the System.Diagnostics namespace
MemeZ
MemeZ12mo ago
do i keep the async? on the button the button didn't do anything
Angius
Angius12mo ago
No need for async if you're not awaiting inside
MemeZ
MemeZ12mo ago
thought so but it still didn't work no error just nothing happens @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius12mo ago
Odd, it should work
MemeZ
MemeZ12mo ago
niether did message boxes
Angius
Angius12mo ago
Ah
Process.Start(new ProcessStartInfo() { FileName = "https://google.com", UseShellExecute = true });
Process.Start(new ProcessStartInfo() { FileName = "https://google.com", UseShellExecute = true });
maybe?
MemeZ
MemeZ12mo ago
literally nothing could it be the linking to the button maybe? the settings @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius12mo 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
MemeZ12mo ago
no absolutley nothin what could it be @ZZZZZZZZZZZZZZZZZZZZZZZZZ
Angius
Angius12mo ago
No idea
MemeZ
MemeZ12mo ago
damn
Want results from more Discord servers?
Add your server
More Posts
❔ ✅ Use Reflection or Generics to specify one or more propertiesI'm writing something that will automatically create a table and fill it with data based on the prop❔ What's the difference between `IConfiguration.Get` and `IConfiguration.Bind`?The docs say `Get` "Attempts to bind the configuration instance to a new instance of type T. If this❔ Best place to store a flag globally on ASP.NET CoreHello everyone. What I'm trying to achieve is given a list of users that each have access to 1...N ❔ C# app on LinuxHello , I'm trying to create a C# app on Linux but I think it's just not possible. I tried multiple ❔ Pattern matching on multiple cases with the same-typed membersHello, I am currently stuck with code like this: ```cs public void Foo(Bar bar) { if (bar is Bar1❔ Hosting CoreWCF service in AspNet Core (Kestrel). How do I validate the service is up?The output contains notifications that 1) the Kestrel server is listening on the port I specified an✅ What does "Windows Desktop" as the version in ASP.NET's documentation mean?https://learn.microsoft.com/en-us/dotnet/api/system.configuration?view=windowsdesktop-7.0❔ Number guessing game.I'm trying to make a program that generates a random number between 1-100, let's the user guess till❔ how would I got about making a discord bot.I am not new to coding but completely new to discord bot creation so need some pointers✅ Cannot figure out what I am doing wrong.I am currently taking classes for C#, and im kind of throwing things around with casts and things, i