How To Use Attributes As Mappath In Mvc3
Mar 19, 2011
In mvc1, we can write an attribute as '[NewPath("mainpage", Controller = "BrowsePdts", Action = "Index")]' before Action for 'mappaththen we can do sth. as 'mappath' in webformI just want a navigate in the top of page , as ' book
>> magazine >> fashion 'but what the attribute change to in mvc3?
View 3 Replies
Similar Messages:
Jan 28, 2011
I have this working perfectly
[Required(ErrorMessageResourceName = "ValidationError_Required", ErrorMessageResourceType = typeof(Resources.Resources))]
public string Title { get; set; }
public class LRequiredAttribute : System.ComponentModel.DataAnnotations.RequiredAttribute
[code]...
View 2 Replies
Dec 20, 2010
In my application, I want all dates to display in the MM/DD/YYYY format and I also want the text box to be limited to 10 characters and have a certain class applied to it.
To that end, I made a custom editor template for Date that looks like this:
@ModelType System.Nullable(Of DateTime)
@Html.TextBoxFor(Function(d) d, New With {.class="polkDate", .maxlength="10"})
Then in my view I just can just call @Html.EditorFor(Function(m) m.someDate) and this works pretty well. However, because I'm using TextBoxFor, it doesn't respect the DisplayFormat attribute that's applied to my model class (i.e. it's spitting out the time as well instead of formatting the date).
I would love to use EditorFor so that it would respect the formatting that I want, but you can't add attributes like class and maxlength. I also tried just using the plain old TextBox helper, but I don't know how to make it generate the correct ID so that model binding still works.
View 2 Replies
Sep 23, 2010
What is the difference between those two? If I only want to retrieve the absoluate path to an image on web server, is Server.MapPath safer in any case? I'm using Page.MapPath right now, but it won't work if control was created in WebService since control.Page property become null? Whether Server.MapPath always work?
View 1 Replies
Aug 10, 2010
I am using the following XML structure
<SERVERS>
<SERVER NAME="A1" ID="1"></SERVER>
<SERVER NAME="A2"></SERVER>
<SERVER NAME="A3" ID="3" Parent="XYZ"></SERVER>
<SERVER NAME="A4" ID="4"></SERVER>
<SERVER NAME="A5" Parent="abc" value="10"></SERVER>
<SERVER NAME="A6"></SERVER>
</SERVERS>
I am accessing this xml file by using LINQ to XML in asp.net by using C#. I am able to access all the attributes of an XML node by explicitly specifying the name of the attribute. I want to write query on this xml file which reads all the attribute values of the xml node (In our example the node is SERVER) dynamically means I want to write the query which can read the read the value of the attribute Name & ID from first node, only name from second row, Name, ID & Parent from the third row , Name & ID from the fourth row, Name, Parent & Value from the fifth row & only Name from the sixth row without modifying the existing code every time. Once I add one of the attribute ( for example if I add the attribute ID in the sixth row ) in the above xml file then I dont need to modify my LINQ to XML query. My query should dynamically fetch the total number of attributes & display their values. Is their any way to do this ?
View 2 Replies
Jan 29, 2010
i added a fileupload,a image and a button in my form and i did this code:
Code:
[code]....
and it did not work at all.........
it was just a wild guess to remove the mappath and it worked though
now from the very begining i am having confusion with this mappath.....
so can someone explain me when and where to use mappath and where not to use mappath?
View 15 Replies
Mar 2, 2011
I'm having a bit of trouble loading an XML file with ASP. This is the location of the XML file (it's a UNC url):
\ilife104 eamdiskSharedIntegrationSystemdevDataprcImportFactSetFeedsfileList.xml
And this is my code:
<%
'load the XML file..
Option Explicit
Response.Buffer = True
Dim xml
Set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = False
xml.load (Server.MapPath("\ilife104 eamdiskSharedIntegrationSystemdevDataprcImportFactSetFeedsfileList.xml"))
Dim name, retrieved
name = xml.documentElement.childNodes(0).text
retrieved = xml.documentElement.childNodes(2).text
Set xml = Nothing
%>
It gives the error:
Server.MapPath() error 'ASP 0174 : 80004005'
Invalid Path Character(s)
/ITWeb/Interfaces/je/index.asp, line 9
An invalid '/' or '' was found in the Path parameter for the MapPath method.
View 1 Replies
Feb 24, 2010
I have a WCF service method that's running in a worker thread I spin from another method. I need to map a relative service app path ("~/Templates/a.template") to the physical path ("D:WebTemplatesa.template"), but I can't use HttpContext.Current.Server.MapPath because HttpContext.Current is null in a worker thread. How else can I reach MapPath method?
View 2 Replies
Feb 12, 2011
I have this variable that holds a path. I want to see the result for MapPath using this variable, but I get this error.
string FolderName = "Docs/1/1232"
'Server.MapPath(FolderName)' threw an exception of type 'System.Web.HttpException'
Stack trace: at System.Web.Configuration.UserMapPath.GetPhysicalPathForPath(String path, VirtualDirectoryMapping mapping)
at System.Web.Configuration.UserMapPath.GetPathConfigFilename(String siteID, VirtualPath path, String& directory, String& baseName)
at System.Web.Configura [code].....
View 1 Replies
Jan 20, 2011
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 - 1).Item("ImageURL")
Dim iImgID As Integer = dsImage.Tables(0).Rows(i - 1).Item("ImageId")
Dim physicalName As String = HttpContext.Current.Server.MapPath(ImageURL)
oUpload.DeleteFileFromServer(physicalName, iAdID, iImgID)
In this latter case, HttpContext.Current.Server.MapPath(ImageURL) has a value of Nothing.Is there a way to get the full path for this case?
View 1 Replies
May 6, 2010
I want to make an oledbconnection for my access database. I want to put the connection string in the web.config but I learned that server.mappath does not work in there. I want to use the server.mappath. Can I put the connection sting in a session variable into the global.asax in the session start?
View 2 Replies
Jan 15, 2010
Where does httpcontext.current.server.mappath start?
I don't get it... it doesn't return a path.
My webservice is ran when I debug my application :S.
View 4 Replies
Mar 28, 2011
i want to save a picture in one folder up from there where i call the mappath how can i do that?
for example i am here
c:usersmevstproject
and i want to save the file here
c:usersmevst
i want to do that with mappath in order to work in the server.not only in my pc..
View 9 Replies
Aug 6, 2010
When my ASP.NET site uses documents (e.g. XML), I normally load the document as follows:
Server.MapPath("~DocumentsMyDocument.xml")
However, I would like to move the Documents folder out of the website folder so that it is now a sibling of the website folder. This will make maintaining the documents considerably easier.
However, rewriting the document load code as follows:
Server.MapPath("../../Documents/MyDocument.xml")
results in a complaint from ASP.NET that it cannot 'exit above the top directory'.
how I can relatively specify the location of a folder outside the website folder? I really don't want to specify absolute paths for the obvious deployment reasons.
View 4 Replies
Jan 13, 2011
in my Global.asax I have a timer and every 24 hours it creates an instance of a class and calls a method to send reminder emails with an attachment. In this method I am getting the current HttpContext and using Server.MapPath to get the path to the attachment, but it is always null. I guess this is because Application_End has been called between the last user accessing the site and the method being called.
As a workaround I am setting the timer interval to 19 minutes but I would rather not call the method 36 times a day when only once is required.
Is there any way, apart from hard coding the path, to ensure the HttpContext is not null?
View 5 Replies
Apr 17, 2010
The layout of my web app is C:inetpubwwwroot<sln folder><web app folder>. So the image folder in my web app would be the previous path images.
When I try to save to my images folder from a FileUpload control and use Server.MapPath, it drops my <sln folder>, so the path is incorrect. How do I fix this? I figured Server.MapPath just moved up the folder until it hit a drive, no?
View 4 Replies
Jul 20, 2010
I have a virtual directory setup in IIS6. This maps to a shared network drive.
I can correctly map the path using
string mappedPath = HttpContext.Current.Server.MapPath(path);
I then create a DirectoryInfo object as I want to find some files in the directory.
DirectoryInfo updateDirectory = new DirectoryInfo(mappedPath);
But then updateDirectory.Exists is false?? I can take the string from the mappedPath and copy into Start->Run to get to the path so I know it exists. I am authenticating to the webservice using integrated windows authentication and have permissions to the necessary folders.
Is there something obvious I'm missing in the code? Or is this purely set-up and configuration of IIS etc.?
View 2 Replies
Jan 10, 2011
I have image files stored in "VS_ProjectResourcesImages".
When I use the following code:
String str = Server.MapPath("a.png");
str becomes "VS_Projecta.png".
Why isn't it returning the full path?
View 1 Replies
May 4, 2010
I have a web application that uses Server.MapPath to specify the exact physical path of as part of upload image.
For example if I do Server.MapPath("/")
I get this:
\boswinfs04homeusersweb2676username
I was expecting something like this:
d:folder
I need to use Server.MapPath not only for image upload but several other uses.
View 2 Replies
Mar 21, 2010
This is what I have right now for a file residing on the same server and it works.
Dim FILENAME as String = Server.MapPath("Output.txt")
Dim objStreamWriter as StreamWriter
objStreamWriter = File.CreateText(FILENAME)
dr = myCommand.ExecuteReader()
While dr.Read()
objStreamWriter.WriteLine("{0}|{1}|{2:yyyy-MM-dd}|{3:yyyy-MM-dd}", dr(0), dr(1), dr(2), dr(3))
End While
objStreamWriter.Close()
I was planning on FTPing the file to another server once done but is there a way to do it on a remote server? i.e create a text file on a remote server and write to it? Did not find any instances of that usage. How to use ServerXMLHTTP to replace Server.MapPath in this instance?
View 1 Replies
Sep 8, 2010
I am using multiple sitemaps in my project. they are all registred inside the web.config file.
I have a blog inside my project and I need something below;
Home > Blog > cahngeable_category_name_acordingto_my_value > changable_blog_post_name_according_to_my_value
I have tried the below code but it didn't work. it gives me an error.
[Code]....
View 3 Replies
Feb 9, 2011
When I have this in my web.config then everything works as expected:
<appSettings> <add key="ClientValidationEnabled" value="true"/> <add key="UnobtrusiveJavaScriptEnabled"value="true"/> </appSettings>
The client validation runs.
However if I turn off the second one, unobtrusive, I would still expect that client validation would work. However it seems to me that it still posts back fully to the server instead of client side validation only. Is this a bug in MVC3?
View 2 Replies
Feb 23, 2011
I am having a nightmare with getting a Dropdownlist control to work correctly in my MVC application. I am trying to get a set of values out of an enumeration into SelectListItem which I then present to the DropDownList control as its source. The issue is that I can get the thing to render but the selected value is never set and to top it off when the form is posted the value passed across is 0 instead of the actual value. In the View (Razor Code):
HTML4Strict Code:
@Html.DropDownList("UserRole", new SelectList(Enum.GetValues(typeof(enumUserRoleUserManagement)), user.UserRole), new { @onchange = "submitForm(" + i + ")" })
in the Controller:
Csharp Code:
ViewData["RL"] = new SelectList(userActionsModel.GenerateCombo().AsEnumerable(), "Value", "Text");
And Finally in the model:
Csharp Code:
public IEnumerable<SelectListItem> GenerateCombo()
{
var enumerationValues = Enum.GetValues(typeof(enumUserRoleUserManagement));
var enumerationNames = Enum.GetNames(typeof(enumUserRoleUserManagement));
List<SelectListItem> list = new List<SelectListItem>();
foreach (var value in Enum.GetValues(typeof(enumUserRoleUserManagement)))
{
SelectListItem selectList = new SelectListItem
{
Text = value.ToString(),
Value = value.ToString()
};
list.Add(selectList);
}
//SelectList selectList = new SelectList(list);
return list;}
I have burned soooo much time on this, I will be indebted to anyone that provides a solution.
View 1 Replies
Feb 8, 2011
I tried upgrading the solution to MVC3 in VS2010 by using an upgrader tool I don't know what it does exactly but it didn't work. My "System.Web.Mvc" is not being recognized in my project. Is there anything specific I should be doing with my web.config? I don't quite understand the underlying details about all the places I should be referencing dll's or what "binding" even means and when I should use it inside the web.config So I have to ask, what is the best method for upgrading to MVC3 and what have you done that works?
View 1 Replies
Mar 29, 2011
I am using MVC3 with LinQ and Entity framework and I want to start applying ajax. Where is the best place to start?
View 3 Replies