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;
                }
        }
    }
}

sexta-feira, 27 de setembro de 2013

c# Mandar Email Com Dll

c# Mandar Email Com Dll
Nesse programa vou ensinar como Fazer uma dll, para que no
programa da web, nao vao essas informacoes.





segunda-feira, 23 de setembro de 2013

domingo, 22 de setembro de 2013

Zip - criar versao 3.5 framework

http://blog.tiagosalgado.com/2011/03/03/criar-um-ficheiro-zip-em-c/

Pegar Informacoes Para Pagina Asp.net c#

Pegar Informacoes Para Pagina Asp.net c#



domingo, 15 de setembro de 2013

C# - Timer / Arquivos / Dois Monitores

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO; 
 // esse using é obrigatorio para usar funcoes arquivo
 
namespace monitor
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            mostra_tela();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
 
        }
 
        public void mostra_tela()
        {
            // Verifica se arquivo existe
            if (File.Exists("c:\\matwin\\encerra.txt")) 
            {
                string arquivo = "c:\\matwin\\encerra.txt";
                StreamReader sr = new StreamReader(arquivo, Encoding.UTF8);
                listBox_mostra.Items.Clear(); // limpa conteudo do listbox
                string linha = sr.ReadLine();
                //Enquanto a variavel linha for diferente de null (nulo) ...
                while (linha != null) 
                {
                    listBox_mostra.Items.Add(linha);
                    linha = sr.ReadLine(); // Lê a prox linhha...
                }
                sr.Close();
            }
            else
            {
                listBox_mostra.Items.Clear();
                listBox_mostra.Items.Add("Esperando Encerramento");
                // Caso nao existir o arquivo 
            }
        }
 
        private void timer1_Tick(object sender, EventArgs e)
        {
            mostra_tela(); // funcao timer chama mostra_Tela
        }
 
        private void listBox_mostra_SelectedIndexChanged(object sender, EventArgs e)
        {
 
        }
 
    }
}