How to save the correct location of file in table? getting error is not a valid virtual path - asp.net

I was trying to upload some images in my website using input type=file in my asp.net mvc project.while storing the image I used the following code and it is saving the image successfully.
var path2 = Path.Combine(Server.MapPath("~/Images"), filename.jpg);
artwork.SaveAs(path2);
After that I need to save the whole link ( http://example.com/Images/filename.jpg) into my table column.
for that i tried this
tablename.imagelink = path2 ;
then in table column I am getting like
D:\xxxxx\yyyy\example\Images\filename.jpg
then i tried to save the whole link directly
tablename.imagelink = Path.Combine(Server.MapPath("http://example.com/Images/"), filename.jpg);
at that time I am getting an error: "is not a valid virtual path error"
How to solve this. ?

Server.MapPath requires the virtual path of the web server, and you get the error because you're passing the full path like this:
Server.MapPath("http://example.com/Images/")
You need to keep using this:
Server.MapPath("~/Images")

Related

Is it possible to get physical path of uploaded file using js/jquery?

I am trying for getting uploaded files actual physical path using JS or Jquery.
Currently I tried var tmppath = URL.createObjectURL(file);
Its proving temp path like
blob:http://fiddle.jshell.net/b298c63f-9501-4b09-b62e-c5eb01d4aaf3

What causes a HTTP 404 error when using GroupDocs viewer?

I'm using an XPS file reader to produce HTML output via the GroupDocs Viewer, and it's giving a result in HTML format using the UseHtmlBasedEngine property but giving me error in top corner of viewer like HTTP Error 404.0 not found.
string fileName = (sender as LinkButton).CommandArgument;
string scriptLibraries = Viewer.CreateScriptLoadBlock().LoadJquery().LoadJqueryUi().ToString();
string inlineDocPreviewScript = Viewer.ClientCode()
.TargetElementSelector("#divShow")
.FilePath(fileName)
.EnableRightClickMenu(true)
.ShowThumbnails(true)
.OpenThumbnails(true)
.ZoomToFitWidth()
.Quality(100)
.MinimumImageWidth(ImageWidth)
.UseHtmlBasedEngine(true,true,true,true)
.ToString();
HeadControl.Controls.Add(new Literal() { Text = scriptLibraries });
BodyControl.Controls.Add(new Literal() { Text = inlineDocPreviewScript });
How to resolve HTTP 404.0 not found error in this scenario?
Looks like you have changed the root URL of the application or have generated document’s cache with a URL and then changed it or deployed the application to another server. To resolve the issue, simply delete the Viewer cache – the "temp" folder, which can be found in the root storage path (which you’ve set in the .SetRootStoragePath() method).
If this will not help you, please share with us the following details: which type of the project you use (We3b Forms or MVC) and a code example of the Viewer initialization and web.configs.
As for the reading html and image files from different folders - please provide more info about the use case because it's not very clear what you actually want to do. Please post your request on our support forum at: http://groupdocs.com/Community/Forums/Default.aspx

Persits.MailSender.4 error '800a0007' upon calling objMail.AddEmbeddedImage

I'm using Persits AspEmail for sending emails in a Classic ASP application. I've used it many times before but I had never come across the following issue:
I need to embed an image into the body of an email, but this image is actually virtual (I'm using IIS Rewrite to handle all URL rewrites, so when an image is requested from a specific directory, IIS Rewrite calls an .asp page that displays the image using the Persits AspJpeg component), but when I try to do it, AspEmail returns this error:
Persits.MailSender.4 error '800a0007'
The system cannot find the path specified.
Any other image that is not virtual will get embedded.
The code is simple:
Set objMail = Server.CreateObject("Persits.MailSender")
...
objMail.AddEmbeddedImage virtualImageUrl, virtualImageCid
...
objMail.Send
Am I doing something wrong here? If AspEmail can't handle virtual files, is there a way around this? Please, other than using FSO to temporarily copy the file to a directory in order to embed it, or leaving the image on the server -- I really need it to be embedded.
Thank you (a lot!) in advance,
Cheers,
Mark
P.S.: My server is running IIS 7.5 / IIS Rewrite Module 2 / AspEmail v5.1.0.3.
AddEmbeddedImage property needs a physical path. And it doesn't make an http request (to getting dynamic script response).
4.2 The AddEmbeddedImage Method (http://www.aspemail.com/manual_04.html#4_2)AspEmail offers support for embedded images via the method AddEmbeddedImage which takes two arguments:
the physical path to an image file, and its Content ID, which is simply an
arbitrary string without spaces.If your message contains multiple
embedded images, each must be assigned a unique Content ID.
But there is another property more appropriate than AddEmbeddedImage to using dynamic images.
You need make an http request and pass the response to your AspEmail instance using AddEmbeddedImageMem property.
Similar solution: embed google qrcode in email
Here's what I did:
Since I'm also using Persits AspJpeg to generate the virtual image, I used the objAspJpeg.Binary property to save the image temporarily to a variable, and then passed this variable to objMail.AddEmbeddedImageMem method, and voilà.
'First: AspJpeg to process and generate the virtual binary image.'
Set objAspJpeg = Server.CreateObject("Persits.Jpeg")
objAspJpeg.Open(Server.MapPath(physicalImgUrl)) 'Actual, physical image.'
'...some image processing: resizing, etc...'
processedVirtualImg = objAspJpeg.Binary 'Generated virtual image.'
Set objAspJpeg = Nothing
'Second: AspEmail to embed the virtual image and send the email.'
Set objMail = Server.CreateObject("Persits.MailSender")
objMail.Host = "www.example.com"
'< the rest of the config parameters here >'
objMail.Body = "<img src=""cid:virtualImgId"" />"
objMail.IsHTML = True
objMail.AddEmbeddedImageMem "image.jpg", "virtualImgId", processedVirtualImg
objMail.Queue = True
objMail.Send
Set objMail = Nothing

how can get image from a relative path

i am working in asp .net mvc3.
i want to get a image which exist in this location in my project
G:\projects\CalcoWoms\CalcoWOMS\Content\pictures\calcologo.png
CalcoWOMS is my project name. i want to fetch this calcologo.png in following line please check following line and tell me how should write this following line in correct way.?
iTextSharp.text.Image gif = iTextSharp.text.Image.GetInstance("~/calcologo.png");
means in place of ("~/calcologo.png"); what path i should write ?
You could use MapPath
var physicalPath = Server.MapPath("~/Content/pictures/calcologo.png");
You could try "%~dp0calcologo.png".
%~dp0 means current directory.
You could use the HostingEnvironment object along with Path.Combine
Path.Combine(#HostingEnvironment.ApplicationPhysicalPath, "calcologo.png");
Of course, #HostingEnvironment.ApplicationPhysicalPath will only take you to the root of your application, so you might need to use "Content/picturescalcologo.png".

Get file upload data from post data in ASP.NET

I am looping through the posted values on a form with a view to doing something with them (so don't have access to the controls themselves). This is the process I have to take on this project so that is why I'm doing it this way.
On the form I will have a file upload box but I am not sure how I would upload the file that has been selected from it as I can't just do Control.SaveAs(). When I return the posted value using Request.Form.Item[i] I get the file name I chose but not the full path like I would expect.
Can someone point me in the right direction please?
Thanks.
If you want to manipulate the uploaded files directly, and not through a FileUploader control, you should use the Request.Files collection and not the Request.Form
File Upload controls only pass the file name and the contents. I'm not sure why you would need a folder name, especially since the folder name would be for the client - I can't expect that this would have any value to you since you want to save the file on the server.
As I am unsure of your goals, I would recommend using Server.MapPath("~/Folder") to find a suitable folder to save your uploaded files to

Resources