Category Archives: FileUpload

[RESOLVED] Email Attatchment

Hi,

I am unsure of the best method to send an email with an attachement.
I am using it on a page .aspx - vb.net that is for careers and I want them to send a resume as an attachment.

I have got it working fine with Internet Explorer using the file control as it has the full path to the file.
with every other browser it only has the filename and therefore fails.  

Could you please let me know the best approach here.

Thanks
Michael 

Hi,

I would suggest you to use JQuery file upload, which will work across all the browsers.

What i would suggest you first upload the resume on your server local directory say for example in Temp and than attached it from that temp directory send the email,

Once email successfully sent than remove it from that temp directory or if you want to save it from further than kept it where you want.

 

Use the jquery file uploader...Save the file name & file storage path  and save the attached file in application folder.

At the retrieving time use the id of the file name & fetch it from the folder where u have uploaded.

Hello Mica07

 

Please have a look at the following article http://www.codeproject.com/KB/aspnet/SivaEMailSample.aspx

Here you can create a interface and can ask users to upload files(attachment) using fileupload control.

string attach_item = null;

Hi,

 

Try this

        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)

        {

            attach_item = ds.Tables[0].Rows[i]["TemplatePath"].ToString(); ;

            Email1.Attachments.Add(new System.Net.Mail.Attachment(attach_item));

        }

[RESOLVED] Randomly generated filename with FileUpload Control

Hi all, I have a FileUpload control that currently uploads pics to the Photos folder on my server. What I would like to know is how would I give it a randomly generated filename when it gets uploaded? As I don't want duplicates later on down the line. Cheers. (Code below).

 

<h2>Step 2: Add Photos</h2>
<p>
    <asp:FileUpload ID="FileUpload1" runat="server" />
    <asp:RegularExpressionValidator runat="server" ID="valUpTest" ControlToValidate="FileUpload1" ValidationGroup="up"
            ErrorMessage="Image Files Only (.jpg, .bmp, .png, .gif)"
            ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.jpg|.JPG|.gif|.GIF|.jpeg|.JPEG|.bmp|.BMP|.png|.PNG)$" />
</p>
<p>
    <asp:Button ID="btnUpload" runat="server" Text="Upload"
        onclick="btnUpload_Click" CausesValidation="true" />
</p>

 

Code Behind:

protected void btnUpload_Click(object sender, EventArgs e)
        {
            string path = Server.MapPath("~/Images/Photos/") + FileUpload1.PostedFile.FileName.ToString();
            FileUpload1.SaveAs(path);
        }

how about using a guid as the filename:

string s = Guid.NewGuid.ToString("N") ;

A simple and easy way is to combine [filename]+year+day+mins+seconds. you will have to remove the / and :  so it will come out like  pic1-20111680015. This will make sure you never have duplicate names

 

Thanks guys using a combination of both of your techniques I have managed to do it (code is below if anyone should need this in the future).

 

protected void btnUpload_Click(object sender, EventArgs e)
        {
            string fileName = "pic" + DateTime.Now.ToString("yyyy/dd/mm/ss").Replace("/", "");

            string path = Server.MapPath("~/Images/Photos/");
            FileUpload1.SaveAs(path + fileName);
        }

 

[RESOLVED] Add control dynamically

Asslam-o-Alaikum

Can i add file Upload control dynamically on Runtime / or on Client side browser

Actually the problem is that i give option to user for upload file & he/she upload file 1 or more than 1 10....

& there is no limit for add file upload control 

Can i add control dynamically on client side / or runtime ........

if yes than please help me.............................

 

 

I haven't tried it by myself; but just check out this nice multiple file upload using ajax: Multiple FileUploader AJAX :: ASP.NET

 

hope it helps./.

You can.
However, you would still need to be able to get the value back during the postback sequence. You may find these in the Request.Form values.

A different approach would be to use some kind of AJAX file uploader.

Just did a POC for you. Please verify the code.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Button runat="server" ID="btnAddFileUploadControl" Text="Add File Upload Control" />
            <div runat="server" id="divUploadControls" />
        </div>
    </form>
</body>
</html>

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

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        btnAddFileUploadControl.Click += new EventHandler(btnAddFileUploadControl_Click);
        if (!IsPostBack)
        {
            AddUploadControls(1);
            ViewState["UploadControlsCount"] = 1;
        }
        
    }

    void btnAddFileUploadControl_Click(object sender, EventArgs e)
    {
        int count = Convert.ToInt32(ViewState["UploadControlsCount"].ToString());
        count++;
        ViewState["UploadControlsCount"] = count;
        AddUploadControls(count);
    }

    private void AddUploadControls(int upLoadControlsCount)
    {
        for (int i = 0; i < upLoadControlsCount; i++)
        {
            divUploadControls.Controls.Add(new FileUpload());
        }        
    }
}

Try this...

Joe Stager gave a very reasonable code...

http://www.asp.net/general/videos/how-do-i-multiple-file-uploads-in-aspnet-1

Thanks.

Hi,

Thanks you so much fo providing the link. It is really good. I'll add this to my favourite list.

[RESOLVED] reading a doc file in asp.net

how can i read a doc file and show it on webpage like if someone upload his/her resume one can see upload resume in asp.net page like monster.com and other job portal side do.Any idea pls Help its urgent

Hi,

for read the doc file in asp.net first you need to add the referance of Microsoft.office.tools.word     8.0.0.0

by add reference in your project.

After that using the fileupload to upload the Doc file and store in your project.

After that on some event like.

 

protected void btn_Click(object sender, EventArgs e)

{

Word.ApplicationClass wa = new Word.ApplicationClass();

string path = fileupload1.Value;

object file = path;

object nullobjct = System.Reflection.Missing.Value;

Word.Document doc = wa.Documents.Open(file,
ref nullobjct, ref nullobjct,ref nullobjct, ref nullobjct, ref nullobjct,
ref nullobjct, ref nullobjct, ref nullobjct,ref nullobjct, ref nullobjct,
ref nullobjct);

Word.Document doc1 = wa.ActiveDocument;

string m_Content = doc1.Content.Text;

m_Textbox.Text = m_Content;

doc.Close(refnullobjct , ref nullobjct, ref nullobjct);

 

I have tried this code you just take the idea from this.

It will work. Let me know if you are facing some problem.

The provided link by Mr khan its nice

I have also try this.

http://www.aspsnippets.com/Articles/Convert-Office-Word-Document-to-HTML-and-display-it-in-browser-in-ASP.Net.aspx