Showing posts with label uploading. Show all posts
Showing posts with label uploading. Show all posts

Saturday, March 24, 2012

Problem during Uploading the file

Hi

The Problem that am facing is

1)The path of the file that is saving in the database is "Path of the Server" + "images/"Up" of the path variable. I dont know why.

2) When i click on the Save Button, the code says File Uploaded but the file is missing from the location. Actually i think that "SaveAs" function is not working properly.

Boolean fileOK = false;
String path = Server.MapPath("/images/Uploads/employee/images/");
if (!(Directory.Exists(path)))
{
Directory.CreateDirectory(path);
}
lblInformation.Visible = true;
if (fuplEmployeeImage.HasFile)
{
String fileExtension = System.IO.Path.GetExtension(fuplEmployeeImage.FileName).ToLower();
String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}

if (fileOK)
{
if (File.Exists(path + fuplEmployeeImage.FileName))
{
lblInformation.Text = fuplEmployeeImage.FileName + " already Exists.Please Rename the file and try again.";
}
else
{
try
{
fuplEmployeeImage.PostedFile.SaveAs(path + fuplEmployeeImage.FileName);
_prEmployee.Attachment = path + fuplEmployeeImage.FileName;
lblInformation.Text = fuplEmployeeImage.FileName + " File Uploaded!";
}
catch (Exception ex)
{
lblInformation.Text = fuplEmployeeImage.FileName + " File could not be Uploaded.";
}
}
}
else
{
lblInformation.Text = "Cannot accept files of this type.";
}
}

Any help is greatly appreciated.

Thanx

If you're using AJAX with the FileUpload control, it's never going to work. See this thread for more details:

http://forums.asp.net/t/1107788.aspx


Hi

Thanx for your response.

I know this thing that File Upload Control doesn't work inside Update Panel of AJAX.For that purpose i had fire PostBacktrigger for thec control which actually calls FileUpload Control.

So that is not an issue

Bye


Hi,deepakleo2003

I'd like to give you a demo:

<%@. Page Language="C#" %>
<%@. Import Namespace="System.IO" %>

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

<script runat="server">

protected void Button1_Click(object sender, EventArgs e)
{
Boolean fileOK = false;
String path = Server.MapPath("images/");
if (!(Directory.Exists(path)))
{
Directory.CreateDirectory(path);
}
lblInformation.Visible = true;
if (fuplEmployeeImage.HasFile)
{
String fileExtension = System.IO.Path.GetExtension(fuplEmployeeImage.FileName).ToLower();
String[] allowedExtensions = { ".gif", ".jpg", ".png", ".jpeg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
break;
}
}

if (fileOK)
{
if (File.Exists(path + fuplEmployeeImage.FileName))
{
lblInformation.Text = fuplEmployeeImage.FileName + " already Exists.Please Rename the file and try again.";
}
else
{
try
{
fuplEmployeeImage.PostedFile.SaveAs(path + fuplEmployeeImage.FileName);
//_prEmployee.Attachment = path + fuplEmployeeImage.FileName;
lblInformation.Text = fuplEmployeeImage.FileName + " File Uploaded!";
}
catch
{
lblInformation.Text = fuplEmployeeImage.FileName + " File could not be Uploaded.";
}
}
}
else
{
lblInformation.Text = "Cannot accept files of this type.";
}
}
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblInformation" Visible="false" runat="server" Text="lblInformation"></asp:Label>
<asp:FileUpload ID="fuplEmployeeImage" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div>
</form>
</body>
</html>

If this help you,don't forget mark it as a answer.Thanks!

Let me know if you need more info.

Wednesday, March 21, 2012

Problem in file uploading with Ajax

I want to upload an image on server. My source below is working well. But when I keep the same things in Update Panel it didn't work. Can some one help me on this strange behavior please?

Thanks!

ImageUpload.aspx.cs
 
using System;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
 
namespace Articles
{
   publicclass Default : Page
   {
       public HtmlInputFile   Picture;
       public Label           Message;
       public Image           UploadedPic;
 
       publicvoid UploadImage(object sender, EventArgs e)
       {
           if (Picture.PostedFile !=null)
           {
               string PicType = Picture.PostedFile.ContentType.ToString();
               if (PicType == "image/jpeg" || PicType == "image/gif" || PicType == "image/pjpeg"
                   || PicType == "image/bmp")
               {
                   try
                   {
                       string PicName = Picture.PostedFile.FileName;
                       string NewPicName = (string)Session.SessionID + "_" + PicName.Substring(PicName.LastIndexOf(@dotnet.itags.org."\")+1);
                       string UploadPath = Request.PhysicalApplicationPath + @dotnet.itags.org."\Upload\";
 
                       Picture.PostedFile.SaveAs(UploadPath + NewPicName);
 
                       Message.Text = "Picture successfully uploaded to server!";
                       UploadedPic.AlternateText = "Uploaded picture...";
                       UploadedPic.ImageUrl = UploadPath + NewPicName;
                       UploadedPic.Visible =true;
                   }
                   catch (Exception exc)
                   {
                       Message.Text = exc.ToString();
                   }
               }
               else
                   Message.Text = "File format not supported!";
           }
       }
   }
}

ImageUpload.aspx
 
<%@dotnet.itags.org. Page Language="C#" Codebehind="ImageUpload1.aspx.cs" Inherits="Articles.Default" %>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<html>
<head>
<title>Image Upload #1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body>
 
<h3>Image Upload #1</h3>
<form enctype="multipart/form-data" runat="server">
   <table>
       <tr>
           <td>Image:</td>
           <td><input id="Picture" type="file" runat="server"/></td>
       </tr>
   </table>
   <br/>
   <input type="submit" value="Upload >>>" onserverclick="UploadImage" runat="server"/>
</form>
 
<asp:label id="Message" runat="server"/>
 
<hr>
 
<asp:image id="UploadedPic" visible="False" runat="server"/>
 
</body>
</html>

Hi,

unfortunately the FileUpload control, like some other controls, don't work together with the UpdatePanel. So no go.

You can check the controls out that don't work with it here:

Taken from the documentation:http://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx

Controls that Are Not Compatible with UpdatePanel Controls

The following ASP.NET controls are not compatible with partial-page updates, and are therefore not supported inside anUpdatePanel control:

TreeView andMenu controls.

Problem in uploading ajax toolkit on web server

Respected Sir,

I have used Dropshow simple control in ajax control tool kit,

it's all run on localhost, but it's gave problem on web server which i deployed hall application

The error is as shown below:

It shows thatCould not found Micosoft.Extension.Design.Dll

I can solve that error by copying that dll file on my bin folder in server,

But how can i permanently removed that error ,

can you explain me ?

What ajax version i have to download for that ? pls give me proper guidance.

i m waiting for you response.

Happy Coding !

You can reference the Micosoft.Extension.Design.Dll into your project or add the Micosoft.Extension.Design.Dll into the GAC usint GACUTIL.EXE will install the dll into the gac.Hope this helps