Upload de arquivos RRS feed

Todas as Respostas

  • ?

    quinta-feira, 20 de março de 2008 19:30


    Arquivo upload.aspx.vb

    Dim savePath As String = "c:\"
    Sub Upload_Click(ByVal source As Object, ByVal e As EventArgs)

    Dim Loop1 As Integer
    Dim TempFileName As String
    Dim MyFileCollection As HttpFileCollection = Request.Files

    Dim PosFinal As Integer
    Dim NomeRvs As String
    Dim NomeArq As String

    For Loop1 = 0 To MyFileCollection.Count - 1
    PosFinal = InStr(StrReverse(MyFileCollection(Loop1).FileName), "\")
    If PosFinal > 0 Then
    'MyFileCollection(Loop1).FileName = "C:\"
    'StrReverse() = piz.oizav\
    NomeRvs = StrReverse(MyFileCollection(Loop1).FileName)
    NomeArq = StrReverse(Mid(NomeRvs, 1, PosFinal - 1))
    message.Text += "<br><br>Upload de " & NomeArq

    TempFileName = savePath & NomeArq
    'Salva o Arquivo
    End If
    Catch exc As Exception
    message.Text = "Erro na Transferência"
    End Try
    Next Loop1

    End Sub

    Arquivo upload.aspx

    <form id="Form1" encType="multipart/form-data" runat="server">
    Selecione o arquivo a ser transferido:
    <input id="uploadedFile" type="file" name="uploadedFile" runat="server"><br>
    <input id="uploadedFile2" type="file" name="uploadedFile2" runat="server">
    <p><input id="upload" type="button" value="Enviar" name="upload" runat="server" onserverclick="Upload_Click">
    <asp:Label id="message" runat="server" /></p>

    Upload em C#
    <%@ Page debug="true" %>

    <script language="c#" runat="server">

    void Page_Load(Object sender, EventArgs e)
    if (Page.IsPostBack)

    System.Boolean SaveImages()
    System.Web.HttpFileCollection colFiles = System.Web.HttpContext.Current.Request.Files;
    System.Text.StringBuilder strMessage;
    strMessage = new System.Text.StringBuilder("Files Uploaded:<br><br>");
    System.Int32 intFileCntr;


    for (intFileCntr = 0; intFileCntr < colFiles.Count; intFileCntr++)

    System.Web.HttpPostedFile objCurrentFile = colFiles.Get(intFileCntr);
    System.String strCurrentFileName;
    System.String strCurrentFileExtension;

    strCurrentFileName = System.IO.Path.GetFileName(objCurrentFile.FileName);

    if(strCurrentFileName != "")

    strCurrentFileExtension = System.IO.Path.GetExtension(strCurrentFileName);

    if (strCurrentFileExtension == ".gif" || strCurrentFileExtension == ".jpg")

    objCurrentFile.SaveAs("\\\\premfsx\\sites\\premiumx\\xxxxxxxx\\database\\images\\" + strCurrentFileName);

    strMessage.Append(strCurrentFileName + " successfully uploaded.<BR>");
    strMessage.Append(strCurrentFileName + " <font color='red'>failed!! Only .gif and .jpg images allowed!</font> <BR>");

    Label1.Text = strMessage.ToString();
    return true;
    catch (System.Exception Ex)
    Label1.Text = Ex.Message;
    return false;

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <title>::: UPLOAD SAMPLE ::: </title>
    <form id="UPLOAD" method="post" runat="server" enctype="multipart/form-data">
    <h3>Multiple File Upload Example</h3>
    <INPUT type="file" runat="server" size="50" ID="File1" NAME="File1"></P>
    <INPUT type="file" runat="server" size="50" ID="File2" NAME="File2"></P>
    <INPUT type="file" runat="server" size="50" ID="File3" NAME="File3"></P>
    <INPUT type="file" runat="server" size="50" ID="File4" NAME="File4"></P>
    <INPUT type="file" runat="server" size="50" ID="File5" NAME="File5"></P>
    <P><STRONG>:: </STRONG>
    <asp:LinkButton id="LinkButton1" runat="server" Font-Names="Verdana" Font-Bold="True" Font-Size="XX-Small">Upload Images</asp:LinkButton> <STRONG>::
    </STRONG> <A href="java scriptBig Smileocument.forms[0].reset()" id="LinkButton2" style="FONT-WEIGHT:bold;FONT-SIZE:xx-small;FONT-FAMILY:verdana">
    Reset Form</A> <STRONG>::</STRONG></P>
    <asp:Label id="Label1" runat="server" Font-Names="verdana" Font-Bold="True" Font-Size="XX-Small" Width="400px" BorderStyle="None" BorderColor="White"></asp:Label></P>
    <P> </P>

    quinta-feira, 20 de março de 2008 19:33