Hi I want to send a photo with my telegram bot but my VS doesn’t recognize “FileToSend” and my error is :
int chatId = int.Parse(dgReport.CurrentRow.Cells[0].Value.ToString());
FileStream imageFile = System.IO.File.Open(txtFilePath.Text,FileMode.Open);
bot.SendPhotoAsync(chatId, new FileToSend("1234.jpg", imageFile), txtmessage.Text);
CS0246 The type or namespace name ‘FileToSend’ could not be found (are
you missing a using directive or an assembly reference?)
3
Answers
Sounds like you are very new to Visual Studio and also C# so I’ll share a general tip. If you see a red squiggly line in Visual Studio you have a compile error. Your program will not build/run until it is fixed.
Here’s my tip. Find the code that is causing the compile error (the text with a red squiggle beneath it). Right click the text and choose “Quick Actions and Refactoring”. You will see several suggestions that may fix the issue.
The problem you are describing can usually be fixed using this feature. One of the options may be something like “Using Telegram.Bot;”. If you choose it, it will automatically put the using statement at the top of your file and fix the compilation error. This is definitely the #1 reason I use Quick Actions and Refactoring.
Actually, the question is quite OK. I think you just might be mixing up examples you’ve found and tried, which – if so – is an honest mistake. The
FileToSend()
function is related to a (deprecated) project on GitHub at ScottRFrost/TelegramBot.The rest of your sample seems to be mixed up a bith with, I assume, the TelegramBots/Telegram.Bot package. If you use that, the following sample might help you a bit further:
As you can see, no
FileToSend()
in there, which might be the cause of your problem.Note that this is just to help you in the right direction; it is not meant as code to be used in production. Especially reading out the stream through
File.Open
could be improved.The
FileToSend()
function is removed, useInputOnlineFile()
: