Uploading Excel File using Flex & ASP.Net


This is an Example  of Upload file with Flex.. the version of this component is for Flex 2 but works with Flex 3

URL of FileUpload Component : http://www.cristianhernandez.org/blog/?p=67

sourcecode of the component: http://www.cristianhernandez.org/blog/wp-content/flex/upload/srcview/index.html

ActionScript Code for upload:

public function selectHandler(event:Event):void
{
//mx.controls.Alert.show(fileRef.name,’fileRef.name’);
var request:URLRequest = new URLRequest(”http://localhost/Admision/Default.aspx”);
request.method = URLRequestMethod.POST;
var variables:URLVariables = new URLVariables();
variables.usuario = “LOKI”;
request.data = variables;
try
{
fileRef.upload(request);
textarea1.text = “Enviando ” + fileRef.name + “…”;
}
catch (error:Error)
{
mx.controls.Alert.show(’No se puede Enviar el Archivo’,’Error’);
}
}
.Net Code for upload:
protected void Page_Load(object sender, EventArgs e)
{
string uploadFolder = “upload”;
HttpFileCollection files = Request.Files;
if (files.Count == 0)
{
Response.Write(”No se encontraron Archivos”);
Response.End();
}
string path = Server.MapPath(uploadFolder);
HttpPostedFile file = files[0];
if (file != null && file.ContentLength > 0)
{
string archivo = Request.Form[”fileName”];
string usuario = Request.Form[”usuario”];
string extension = (archivo.EndsWith(”.jpg”)) ? “.jpg” : “.gif”;
if ((archivo.EndsWith(”.jpg”)) || (archivo.EndsWith(”.gif”)))
{
string savePath = path + “/” + usuario + extension;
file.SaveAs(savePath);
}
}
}
sourcecode: Comment of LOKI in

http://www.cristianhernandez.org/blog/?p=43

~ by mjcprasad2000 on March 27, 2009.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: