简体   繁体   English

如何重命名上传的文件?

[英]how to rename uploaded file?

I made a form in ASP.NET with VB background code. 我用VB背景代码在ASP.NET中创建了一个表单。 my problem is I want to make that the file which is been uploaded to by the form to change to "Resemey.doc" instead for example "012 MaraCSD.doc" 我的问题是我想使表单上传到的文件更改为“ Resemey.doc”,例如“ 012 MaraCSD.doc”

did a bit of research and found out I need to add some code to my vb code. 做了一些研究,发现我需要在vb代码中添加一些代码。 but couldn't find what, and where to put it. 但找不到什么东西,放在哪里。

this is my code: 这是我的代码:

'Add the namespace for the email-related classes
Imports System.Net.Mail

Partial Class SendAttachment    
    Inherits System.Web.UI.Page   

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        'Make sure a file has been uploaded

        If String.IsNullOrEmpty(AttachmentFile.FileName) OrElse AttachmentFile.PostedFile Is Nothing Then
            Throw New ApplicationException("לא העלאת קבצים.")
        End If

        if AttachmentFile.PostedFile.ContentLength >600000 then   
          'display error file size should be less than 100kb   
        end if


        '!!! UPDATE THIS VALUE TO YOUR EMAIL ADDRESS
        Const ToAddress As String = "pelleg@gmail.co.il"
        dim textMsg as String
       textMsg ="שאלות סינון" &
 (vbCrLf)  & (vbCrLf)  & (vbCrLf)  & question1.text & (vbCrLf)  & q1.text & 
(vbCrLf) & (vbCrLf) & question2.text & (vbCrLf) & q2.text & 
(vbCrLf) & (vbCrLf) & question3.text & (vbCrLf) &q3.text & 
(vbCrLf) & (vbCrLf) & "ממליצים" & (vbCrLf) & c1.text & (Space(5)) & c2.text & (Space(5)) & c3.text & (vbCrLf) &
 (vbCrLf) & question4.text & (vbCrLf) & q5.text & (vbCrLf) &
 (vbCrLf) & "פרטים אישיים" & (vbCrLf) & 
(vbCrLf) & "שם מלא" & (vbCrLf) & pi1.text & (vbCrLf) &
 (vbCrLf) & "כתובת מייל" & (vbCrLf) & UsersEmail.Text & (vbCrLf) &
 (vbCrLf) & "טלפון" & (vbCrLf) & pi2.text & (vbCrLf) & 
(vbCrLf) &"שעות נוחות" & (vbCrLf) & pi3.text & (vbCrLf) & 
(vbCrLf) & (vbCrLf) & "הערות"  & 
(vbCrLf)  & body.text & (vbCrLf) & 
(vbCrLf) & "מעוניין בהצעות נוספות" & (vbCrLf) & q4.text 
 '  

        '(1) Create the MailMessage instance
        Dim mm As New MailMessage(UsersEmail.Text, ToAddress)

        '(2) Assign the MailMessage's properties
        mm.Subject = Subject.text &  "-" & pi1.text
        mm.Body = textMsg

        mm.IsBodyHtml = false

        'Attach the file
        mm.Attachments.Add(New Attachment(AttachmentFile.PostedFile.InputStream, AttachmentFile.FileName))
        mm.Attachments.Add(New Attachment(AttachmentFile2.PostedFile.InputStream, AttachmentFile2.FileName))

        '(3) Create the SmtpClient object
        Dim smtp As New SmtpClient

        '(4) Send the MailMessage (will use the Web.config settings)
        smtp.Send(mm)

        'Show the EmailSentForm Panel and hide the EmailForm Panel
        EmailSentForm.Visible = True
        EmailForm.Visible = False
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            'On the first page load, hide the EmailSentForm Panel
            EmailSentForm.Visible = False

        End If
    End Sub
End Class

any ideas? 有任何想法吗?

You should be able to use the SaveAs method of the PostedFile and save it as whatever name you want.. 您应该能够使用PostFile的SaveAs方法并将其保存为所需的任何名称。

http://msdn.microsoft.com/en-us/library/system.web.httppostedfile.saveas.aspx http://msdn.microsoft.com/zh-CN/library/system.web.httppostedfile.saveas.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM