Páginas

terça-feira, 15 de outubro de 2013

Upload - netframework 4.5

Upload - netframework 4.5

       <h4>Selecione um arquivo:</h4>
        <asp:FileUpload id="FileUpload1"  runat="server">
        </asp:FileUpload>
        <asp:Button id="UploadBtn" 
            Text="Upload Arquivo"
            runat="server" OnClick="UploadBtn_Click" >
        </asp:Button>    
        <asp:Label ID="Label_resultado" runat="server" Text="Label"></asp:Label>
        <hr />
 
 
 
   protected void UploadBtn_Click(object sender, EventArgs e)
    {
        string savePath = HttpContext.Current.Server.MapPath("~/arquivos/matos/");
        if (FileUpload1.HasFile)
        {
            string fileName = Server.HtmlEncode(FileUpload1.FileName);
            savePath += fileName;
            FileUpload1.SaveAs(savePath);
            Label1.Text = "Your file was uploaded successfully.";
        } 
 
 
 

Upolad - Ajax



http://stephenwalther.com/archive/2012/05/01/ajax-control-toolkit-may-2012-release

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ajaxfileupload.aspx.cs" Inherits="ajaxfileupload" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>



 xmlns="http://www.w3.org/1999/xhtml">
 runat="server">
    


    
id="form1" runat="server"> ID="ToolkitScriptManager1" runat="server">
runat="server" ID="myThrobber" Style="display: none;"> align="absmiddle" alt="" src="images/uploading.gif"/> ID="AjaxFileUpload1" runat="server" onuploadcomplete="AjaxFileUpload1_UploadComplete" ThrobberID="myThrobber" MaximumNumberOfFiles="10" AllowedFileTypes="jpg,jpeg"/>

 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class ajaxfileupload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
    {
        string filePath = "~/upload/" + e.FileName;
        AjaxFileUpload1.SaveAs(filePath);

    }
}
 

Instalar Ajax tookit

http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AjaxFileUpload/AjaxFileUpload.aspx

http://www.asp.net/web-forms/videos/aspnet-ajax/how-do-i-get-started-with-aspnet-ajax

Instalar Ajax tookit http://ehrizo.wordpress.com/2013/04/23/como-instalar-o-ajaxcontroltoolkit-no-visual-studio-2012-e-utilizar-os-seus-extenders/

domingo, 13 de outubro de 2013

Upload - c# - com %

Upload - c# - com %




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace matosftp
{
    class Program
    {
        static void Main(string[] args)
        {
            mandaFtp();
        }
        public static int mandaFtp()
        {
                Console.WriteLine("Mandando Arquivo para ......");
                string diretorio = "c:\\amarildo\\";
                string nomeArquivo = "copia.zip";
                string ftpServidor = "ftp://ftp.site.com.br/web/arquivos/";
                string USUARIO = "nomeUsuario";
                string SENHA = "senha";
                try
                {
                    FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftpServidor + nomeArquivo);
                    request.Method = WebRequestMethods.Ftp.UploadFile;
                    request.Credentials = new NetworkCredential(USUARIO, SENHA);

                    Stream ftpStream = request.GetRequestStream();
                    FileStream arquivo = File.OpenRead(diretorio + nomeArquivo);
                    FileInfo ArquivoInformacoes = new FileInfo(diretorio + nomeArquivo);
                    int tamanhoArquivo = int.Parse(ArquivoInformacoes.Length.ToString());
                    Console.WriteLine("Tamanho do ARquivo = " + tamanhoArquivo);
                    int tamanho = 1024;
                    byte[] buffer = new byte[tamanho];
                    int bytesread = 0;

                    int somaGeral = 0;
                    long percentual = 0;
                    do
                    {
                        bytesread = arquivo.Read(buffer, 0, tamanho);
                        ftpStream.Write(buffer, 0, bytesread);
                        somaGeral += 1024;
                        percentual =( ( somaGeral * 50 ) / tamanhoArquivo ) * 2;
                        Console.Write("\r{0}...{1}% Andamento...",somaGeral,percentual);
                    }
                    while (bytesread != 0);
                    arquivo.Close();
                    ftpStream.Close();

                    Console.WriteLine();
                    Console.WriteLine("Upload Arquivo Completado");
                    Console.ReadKey();
                    return 1;

                }
                catch (Exception ex)
                {
                    Console.Write(ex);
                    Console.ReadKey();
                    return 2;
                    throw ex;
                }
        }
    }
}