server.mappath

Accessing image from other server

倖福魔咒の 提交于 2019-12-10 11:20:06
问题 I have image file placed on the one server and application on other server. I want to access that image, below code I have written: On default.aspx, I have <asp:Image ID="Image1" runat="server" ImageUrl= "GetImage.aspx?imgName=MyImage.jpg" /> and on GetImage.aspx, I have written the below code on page_load protected void Page_Load(object sender, EventArgs e) { // Changing the page's content type to indicate the page is returning an image Response.ContentType = "image/jpg"; var imageName =

An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Server.get'

依然范特西╮ 提交于 2019-12-10 02:28:59
问题 So I have two functions and I'm getting an interesting problem. Essentially I'm aiming to make my code more portable in an easily includeable cs file. Here's said cs file: namespace basicFunctions { public partial class phpPort : System.Web.UI.Page { public static string includer(string filename) { string path = Server.MapPath("./" + filename); string content = System.IO.File.ReadAllText(path); return content; } public void returnError() { Response.Write("<h2>An error has occurred!</h2>");

Image URL is correct but image not showing

一曲冷凌霜 提交于 2019-12-08 18:48:34
问题 I have a website on GoDaddy. All permissions are set correctly and the image DOES exist. However when the page loads the image for the item selected does not show. Here is my code imagepath = "~/spaimages/" + currentSpaModel.Name.ToString() + ".png"; if (File.Exists(Server.MapPath(imagepath))) { this.spaimage.ImageUrl = Server.MapPath(imagepath); } spaimage is an ASP control and thr URL that the image is set to is D:\hosting\xxxxxxx\calspas\spaimages\modelname.png What am I doing wrong. 回答1:

How to use Server.MapPath when HTTPContext .Current is Nothing

白昼怎懂夜的黑 提交于 2019-12-06 17:24:54
问题 I have some code that works fine when I need to delete some image files from a directory on my web server: Dim ImageURL As String = dsImages.Tables(0).Rows(iImgRow).Item("ImageURL") Dim physicalName = Server.MapPath(ImageURL) oUpload.DeleteFileFromServer(physicalName, iAdid, iImgID) ..but I am running into a problem when a maintenance task running in a separate thread at set intervals determines that files like the above need to be deleted: Dim ImageURL As String = dsImage.Tables(0).Rows(i -

Accessing image from other server

孤街浪徒 提交于 2019-12-06 09:41:43
I have image file placed on the one server and application on other server. I want to access that image, below code I have written: On default.aspx, I have <asp:Image ID="Image1" runat="server" ImageUrl= "GetImage.aspx?imgName=MyImage.jpg" /> and on GetImage.aspx, I have written the below code on page_load protected void Page_Load(object sender, EventArgs e) { // Changing the page's content type to indicate the page is returning an image Response.ContentType = "image/jpg"; var imageName = Request.QueryString["imgName"]; var path = "//SERVER/FOLDER/" + imageName; if ((string.IsNullOrEmpty

How can I use Server.MapPath inside class library project

做~自己de王妃 提交于 2019-12-05 02:38:42
I have a web application thet has a number of class library projects. Some example code below. public static class LenderBL { static string LenderXml { get { return "MyPathHere"; } } public static LenderColl GetLenders() { var serializer = new XmlSerializer(typeof(LenderColl)); using (XmlReader reader = XmlReader.Create(LenderXml)) { return (LenderColl)serializer.Deserialize(reader); } } } I would normally use Server.MapPath to get the path for the property LenderXml, but when I use it in a class library is returns the path of the parent solution, not that of the class library project. Is

An object reference is required for the non-static field, method, or property 'System.Web.UI.Page.Server.get'

懵懂的女人 提交于 2019-12-05 02:28:05
So I have two functions and I'm getting an interesting problem. Essentially I'm aiming to make my code more portable in an easily includeable cs file. Here's said cs file: namespace basicFunctions { public partial class phpPort : System.Web.UI.Page { public static string includer(string filename) { string path = Server.MapPath("./" + filename); string content = System.IO.File.ReadAllText(path); return content; } public void returnError() { Response.Write("<h2>An error has occurred!</h2>"); Response.Write("<p>You have followed an incorrect link. Please double check and try again.</p>");

Use Server.MapPath in Business Layer

◇◆丶佛笑我妖孽 提交于 2019-12-04 04:31:11
My business layer creates files and needs to save them in the App_Data folder of my asp.net mvc 4 web frontend. I could use Server.MapPath in the business layer to get the physical path of the App_Data folder. But i want to avoid a reference to System.Web in the business layer. Are there other ways to get the path to App_Data in business layer? The correct way to deal with this is to have the presentation layer pass the path into the business layer. To put this another way, the purpose of having a business layer is to create a separation of concerns between the ui and business processes. If

C# Unit Testing: Testing a method that uses MapPath

拥有回忆 提交于 2019-12-03 15:14:42
问题 First of all, I am aware that this question is dangerously close to: How to MapPath in a unit test in C# I'm hoping however, that it has a different solution. My issue follows: In my code I have an object that needs to be validated. I am creating unit tests for each validation method to make sure it is validating correctly. I am creating mock data and loading it into the object, then validating it. The problem is that within the validation, when an error occurs, an error code is assigned.

Map the physical file path in asp.net mvc

自古美人都是妖i 提交于 2019-12-03 06:29:19
问题 I am trying to read an XSLT file from disk in my ASP.Net MVC controller. What I am doing is the following: string filepath = HttpContext.Request.PhysicalApplicationPath; filepath += "/Content/Xsl/pubmed.xslt"; string xsl = System.IO.File.ReadAllText(filepath); However, half way down this thread on forums.asp.net there is the following quote HttpContext.Current is evil and if you use it anywhere in your mvc app you are doing something wrong because you do not need it. Whilst I am not using