none
Upload de arquivos RRS feed

Todas as Respostas

  • ?

    []s.
    quinta-feira, 20 de março de 2008 19:30
  • http://www.macul.eti.br/tecnologia/microsoft/aspdotnet/upload.htm

     

    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
    Try
    PosFinal = InStr(StrReverse(MyFileCollection(Loop1).FileName), "\")
    If PosFinal > 0 Then
    'MyFileCollection(Loop1).FileName = "C:\vazio.zip"
    'StrReverse() = piz.oizav\
    NomeRvs = StrReverse(MyFileCollection(Loop1).FileName)
    'vazio.zip
    NomeArq = StrReverse(Mid(NomeRvs, 1, PosFinal - 1))
    message.Text += "<br><br>Upload de " & NomeArq

    'c:\Vazip.zip
    TempFileName = savePath & NomeArq
    'Salva o Arquivo
    MyFileCollection(Loop1).SaveAs(TempFileName)
    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:
    <br>
    <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">
    <p>
    <asp:Label id="message" runat="server" /></p>
    </form>


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

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

    void Page_Load(Object sender, EventArgs e)
    {
    if (Page.IsPostBack)
    {
    SaveImages();
    }
    }

    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;

    try
    {

    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>");
    }
    else
    {
    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;
    }
    }

    </script>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>::: UPLOAD SAMPLE ::: </title>
    </HEAD>
    <body>
    <center>
    <form id="UPLOAD" method="post" runat="server" enctype="multipart/form-data">
    <h3>Multiple File Upload Example</h3>
    <P>
    <INPUT type="file" runat="server" size="50" ID="File1" NAME="File1"></P>
    <P>
    <INPUT type="file" runat="server" size="50" ID="File2" NAME="File2"></P>
    <P>
    <INPUT type="file" runat="server" size="50" ID="File3" NAME="File3"></P>
    <P>
    <INPUT type="file" runat="server" size="50" ID="File4" NAME="File4"></P>
    <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>
    <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>
    </form>
    </center>
    </body>
    </HTML>

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