Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 无法打开office open XML文件,因为内容存在问题_Asp.net_Vb.net - Fatal编程技术网

Asp.net 无法打开office open XML文件,因为内容存在问题

Asp.net 无法打开office open XML文件,因为内容存在问题,asp.net,vb.net,Asp.net,Vb.net,我正在尝试将msword文件作为附件发送,而不将文档存储在硬盘上,但如果将文档指定为文本文件(即记事本),则效果非常好。但是,如果将附件指定为word文档,则会附加并发送该文档,但打开时会显示一条错误消息“office open XML文件无法打开,因为内容有问题”。是否有人可以帮助我 Sub sendattachment(S as Object,E as EventArgs) dim EmailMessage as string = "Dear "& firstname.text &a

我正在尝试将msword文件作为附件发送,而不将文档存储在硬盘上,但如果将文档指定为文本文件(即记事本),则效果非常好。但是,如果将附件指定为word文档,则会附加并发送该文档,但打开时会显示一条错误消息“office open XML文件无法打开,因为内容有问题”。是否有人可以帮助我

Sub sendattachment(S as Object,E as EventArgs)
dim EmailMessage as string = "Dear "& firstname.text &"<br>, Please find  attached <br><br>Thank you"
Dim strFrom = "me<support@mymail.com>"
Dim strTo = username.text 
Dim MailMsg As New MailMessage(New MailAddress(strFrom.Trim()), New MailAddress(strTo))  
MailMsg.BodyEncoding = Encoding.Default  
MailMsg.Subject = " Subject"
MailMsg.Body = EmailMessage
MailMsg.Priority = MailPriority.High  
MailMsg.IsBodyHtml = True  
'Smtpclient to send the mail message  
Dim SmtpMail As New SmtpClient  
Dim basicAuthenticationInfo As New system.Net.NetworkCredential("me@theemail.com", "thepassword") 

'Get some binary data
Dim data As Byte() = GetData()
'save the data to a memory stream
Dim ms As New MemoryStream(data)
'create the attachment from a stream. Be sure to name the data with a file and file type

变量来自哪里?你为什么要做两个附件?您将字符串编码为ASCII码,将其放入字节数组中,并将其附加到电子邮件中。
.docx
文件不仅仅是一些ASCII字符。也许您应该进一步研究实际的
.docx
文件是什么样子的。stream变量和第二个附件是一个错误,它已被更正。如我在前面的评论中所说,您没有生成有效的
.docx
文件。您正在生成一个文本文件。
.docx
文件不是文本文件。
.docx
文件是包含XML文件和其他资源的压缩目录。要在.NET中生成有效的
.docx
文件,您需要找到一个能够为您生成文件的库。好的。但是,假定.docx是microsoft word文件是,
.docx
是microsoft word常用的格式。但这并没有改变我在之前的评论中所说的任何事情。提供文本文件仍然无效。如果要提供文本文件,请将扩展名更改为
.txt
SmtpMail.Send(MailMsg)  

end sub

Function GetData() As Byte()
Dim s As String = "this is some text"
Dim data As Byte() = Encoding.ASCII.GetBytes(s)
Return data
End Function 'GetData