В коде ниже, каким -то образом новая мапощая в этом разделе
//Create a new MapiAttachment using the byte array
< /code>
- это то, что генерирует следующую ошибку: < /p>
cs1729 'mapiattachment' не содержит конструктор, который занимает 2
arguments.
< /blockquote>
Есть ли указатели о том, как обойти это? < /p>
private void AttachFileToEmail(MapiMessage email, string filePath)
{
if (!File.Exists(filePath))
{
MessageBox.Show($"File not found: {filePath}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
// Read the file as a byte array
byte[] fileBytes = File.ReadAllBytes(filePath);
// Get the file name
string fileName = Path.GetFileName(filePath);
// Create a new MapiAttachment using the byte array
MapiAttachment attachment = new MapiAttachment(fileName, new MemoryStream(fileBytes));
// Add the attachment to the email
email.Attachments.Add(attachment);
}
catch (Exception ex)
{
MessageBox.Show($"Error attaching file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}`
< /code>
Я также попробовал следующий код, но по -прежнему нет кости, так как я получил еще одну ошибку < /p>
cs1503: аргумент 2: невозможно преобразовать из 'System.io.memorystream' в
'аспериозное.private void AttachFileToEmail(MapiMessage email, string filePath)
{
if (!File.Exists(filePath))
{
MessageBox.Show($"File not found: {filePath}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
string fileName = Path.GetFileName(filePath);
// Read file bytes
byte[] fileBytes = File.ReadAllBytes(filePath);
// Create a memory stream from the file bytes
using (MemoryStream memoryStream = new MemoryStream(fileBytes))
{
// Add the attachment using the correct method
email.Attachments.Add(fileName, memoryStream);
}
}
catch (Exception ex)
{
MessageBox.Show($"Error attaching file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... -this-erro
Добавьте метод ActadeFileToeMail в c# с использованием aspose.mail, но я получаю эту ошибку «Mapiattachment», не содержи ⇐ C#
Место общения программистов C#
1739493554
Anonymous
В коде ниже, каким -то образом новая мапощая в этом разделе
//Create a new MapiAttachment using the byte array
< /code>
- это то, что генерирует следующую ошибку: < /p>
cs1729 'mapiattachment' не содержит конструктор, который занимает 2
arguments.
< /blockquote>
Есть ли указатели о том, как обойти это? < /p>
private void AttachFileToEmail(MapiMessage email, string filePath)
{
if (!File.Exists(filePath))
{
MessageBox.Show($"File not found: {filePath}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
// Read the file as a byte array
byte[] fileBytes = File.ReadAllBytes(filePath);
// Get the file name
string fileName = Path.GetFileName(filePath);
// Create a new MapiAttachment using the byte array
MapiAttachment attachment = new MapiAttachment(fileName, new MemoryStream(fileBytes));
// Add the attachment to the email
email.Attachments.Add(attachment);
}
catch (Exception ex)
{
MessageBox.Show($"Error attaching file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}`
< /code>
Я также попробовал следующий код, но по -прежнему нет кости, так как я получил еще одну ошибку < /p>
cs1503: аргумент 2: невозможно преобразовать из 'System.io.memorystream' в
'аспериозное.private void AttachFileToEmail(MapiMessage email, string filePath)
{
if (!File.Exists(filePath))
{
MessageBox.Show($"File not found: {filePath}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
try
{
string fileName = Path.GetFileName(filePath);
// Read file bytes
byte[] fileBytes = File.ReadAllBytes(filePath);
// Create a memory stream from the file bytes
using (MemoryStream memoryStream = new MemoryStream(fileBytes))
{
// Add the attachment using the correct method
email.Attachments.Add(fileName, memoryStream);
}
}
catch (Exception ex)
{
MessageBox.Show($"Error attaching file: {ex.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/79438044/add-a-method-attachfiletoemail-in-c-sharp-using-aspose-email-but-i-get-this-erro[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия