using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Telerik.Web.UI;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Net;
/// <summary>
/// Summary description for Codes
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class Codes : System.Web.Services.WebService {
public Codes () {
}
[WebMethod]
public string upload(string pathe)
{
string fileName = System.IO.Path.GetFileName(pathe);
string path = Server.MapPath("images/");
string fullPath = path + fileName;
FileUpload fu = new FileUpload();
Stream s = File.OpenRead(pathe);
byte[] buffer = new byte[s.Length];
s.Read(buffer, 0, (int)s.Length);
int len = (int)s.Length;
s.Dispose();
s.Close();
FileStream fs = new FileStream(fullPath, FileMode.Create);
fs.Write(buffer, 0, len);
Bitmap bmp = new Bitmap(fs);
if (System.IO.Path.GetExtension(pathe).Equals(".gif"))
{
bmp.Save(fs, ImageFormat.Gif);
}
else
{
bmp.Save(fs, ImageFormat.Jpeg);
}
bmp.Dispose();
fs.Dispose();
fs.Close();
string fullnam = "images/"+fileName;
return fullnam;
}
}
Eslam Sayed
Member
48 Points
24 Posts
Please help me Fakepath Problem wthen i upload file
Mar 04, 2012 08:43 AM|LINK
i want upload files with client call back using webservice to save file.
when i run the application from IDE it works correctly with IE only, but when i publish the application doesn't work with IE or any browser
becouse file upload send fakepath to webservice
Please help me
this like contents application
http://www.4shared.com/rar/K5ar5I2C/dddd.html
filepath
sathyam
Member
116 Points
105 Posts
Re: Please help me Fakepath Problem wthen i upload file
Mar 04, 2012 09:39 AM|LINK
Hi
First save that file into temp folder in ur website and later use it.
thanks
Eslam Sayed
Member
48 Points
24 Posts
Re: Please help me Fakepath Problem wthen i upload file
Mar 05, 2012 07:50 AM|LINK
i tried this solution but not working with me
Please Help me to solve this problem
the code that i used
ASPX Page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <!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> <script type="text/javascript"> function Button3_onclick() { var path = document.getElementById("File1").value; ret = Codes.upload(path, oncomplete, ontimeout, onerror); } function oncomplete(arg) { document.getElementById("hl").href = arg; document.getElementById("imagethum0").src = arg; } function ontimeout(arg){ alert("timeout"); } function onerror(arg){ alert("error"); } </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <script src="js/jquery-1.6.1.min.js" type="text/javascript"></script> <link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" media="screen" title="prettyPhoto main stylesheet" charset="utf-8" /> <script src="js/jquery.prettyPhoto.js" type="text/javascript"></script> </head> <body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> <Services> <asp:ServiceReference Path="Codes.asmx" /> </Services> </asp:ScriptManager> <input id="File1" type="file" /> <input id="Button3" type="button" value="upload" onclick="return Button3_onclick()" /><br /> <div class="gallery clearfix"> <a id="hl" href="" rel="prettyPhoto" title=""><img id="imagethum0" Height="200px" Width="200px" alt="" /></a> </div> <script type="text/javascript" charset="utf-8"> $(document).ready(function () { $("area[rel^='prettyPhoto']").prettyPhoto(); $(".gallery:first a[rel^='prettyPhoto']").prettyPhoto({ animation_speed: 'normal', theme: 'light_square', slideshow: 3000, autoplay_slideshow: false, social_tools: false }); // $("#custom_content a[rel^='prettyPhoto']:first").prettyPhoto({ custom_markup: '<div id="map_canvas" style="width:260px; height:265px"></div>', changepicturecallback: function () { initialize(); } }); $("#custom_content a[rel^='prettyPhoto']:last").prettyPhoto({ custom_markup: '<div id="bsap_1259344" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6"></div><div id="bsap_1237859" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6" style="height:260px"></div><div id="bsap_1251710" class="bsarocks bsap_d49a0984d0f377271ccbf01a33f2b6d6"></div>', changepicturecallback: function () { _bsap.exec(); } }); }); </script> </form> </body> </html> and ASMX.csusing System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using Telerik.Web.UI; using System.IO; using System.Drawing; using System.Drawing.Imaging; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Net; /// <summary> /// Summary description for Codes /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. [System.Web.Script.Services.ScriptService] public class Codes : System.Web.Services.WebService { public Codes () { } [WebMethod] public string upload(string pathe) { string fileName = System.IO.Path.GetFileName(pathe); string path = Server.MapPath("images/"); string fullPath = path + fileName; FileUpload fu = new FileUpload(); Stream s = File.OpenRead(pathe); byte[] buffer = new byte[s.Length]; s.Read(buffer, 0, (int)s.Length); int len = (int)s.Length; s.Dispose(); s.Close(); FileStream fs = new FileStream(fullPath, FileMode.Create); fs.Write(buffer, 0, len); Bitmap bmp = new Bitmap(fs); if (System.IO.Path.GetExtension(pathe).Equals(".gif")) { bmp.Save(fs, ImageFormat.Gif); } else { bmp.Save(fs, ImageFormat.Jpeg); } bmp.Dispose(); fs.Dispose(); fs.Close(); string fullnam = "images/"+fileName; return fullnam; } }mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Please help me Fakepath Problem wthen i upload file
Mar 05, 2012 07:55 AM|LINK
The path in the FileUpload is the path of the client user machine and hence it is not send to server.
Can you explain why you need that path?
Contact me
Eslam Sayed
Member
48 Points
24 Posts
Re: Please help me Fakepath Problem wthen i upload file
Mar 05, 2012 07:59 AM|LINK
Thank you for your interest
i want this path to pass it to webservice method
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Please help me Fakepath Problem wthen i upload file
Mar 05, 2012 08:02 AM|LINK
You cannot. Modern browsers donot allow you to access the client path information
Contact me
Eslam Sayed
Member
48 Points
24 Posts
Re: Please help me Fakepath Problem wthen i upload file
Mar 05, 2012 08:10 AM|LINK
thanks for reply
Briefly
I want to upload the images asynchronously and displays the thumbnail image and give the image hyperlink path to work with Jquery
mudassarkhan
All-Star
78956 Points
13402 Posts
MVP
Re: Please help me Fakepath Problem wthen i upload file
Mar 05, 2012 08:14 AM|LINK
So for that you need the server path and not client side path
http://www.aspsnippets.com/Articles/Multiple-File-Uploads-Gmail-Style-using-JQuery-and-ASP.Net.aspx
Contact me
Eslam Sayed
Member
48 Points
24 Posts
Re: Please help me Fakepath Problem wthen i upload file
Mar 05, 2012 08:26 AM|LINK
thanks mudassarkhan very much
Eslam Sayed
Member
48 Points
24 Posts
Re: Please help me Fakepath Problem wthen i upload file
Mar 05, 2012 08:32 AM|LINK
please i need ask you about something else
How can i retrive file uploded path to display it as thumbnail