C# - Mapping A Filename To Paths On A Server?
Jun 28, 2010
I have a problem with my code. My code is using the fileupload control to browse for a filename when you add a filename it processes it and the code runs fine on when it lives on local host, but when I put the code on our prodution server it cannot find the filenames listed by user.
For example if I use the upload control to browse to B:MISCH IntiveRPTTOFL_3.csv and the code lives on my localhost which know what that file path means it works, but if the code is moved to a production server it may or maynot know what B:/ is or B:/ maybe mapped to something else. Even if I am browsing to a file on my C drive it will work on if the code is on the machine that the C drive is on, but it will not work if the code is on another machine because obviously that file wouldnt be on that C drive.
Private Function CSV2DataTable(ByVal filename As String) As DataTable
Using MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser(filename)
MyReader.TextFieldType = FileIO.FieldType.Delimited
What can I do in asp.net to make the filename work correctly?
Ok lets say I get the filename and save it as so
FileUploadControl.SaveAs(Server.MapPath("~/") + filename);
now I want to pass the filename to the function above for processing. Do I pass Server.MapPath("~/") + filename as the filename? Also when I am done what do I do to delete the file from the server?
View 1 Replies
Similar Messages:
Oct 4, 2010
i have a table that contains 3 forign keys, 2 of them from the same table when i make Delete Rule Cascade,this error message appears
'Customers' table saved successfully
'Order' table
- Unable to create relationship 'FK_Order_Customers1'.
Introducing FOREIGN KEY constraint 'FK_Order_Customers1' on table 'Order' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints. Could not create constraint. See previous errors. what is solution,as i want when i delete data from master table ,all dependent (child) data automatically deleted, so i use Cascade.
View 2 Replies
Mar 24, 2010
I have my UserControls in a ~/Controls folder in my solution:
/Controls/TheControl.ascx
If specify the following:
<a id="theId" runat="server" href="./?pg=1">link text</a>
ASP.Net seems to want to rewrite the path to point to the absolute location. For example, If the control is on [URL] the link href will be rewritten to read
<a id="munged_theId" href="../../Controls/?pg=1>link text</a>
Why does Asp.Net rewrite these control paths, and is there an elegant way to fix it?
I just want the anchor control to spit out exactly what I tell it to!!! Is that so hard?
EDIT:
I've basically done what Kelsey suggested. I knew I could do it this way, but I don't like adding markup in my code when I want something relatively simple. At least it solves the problem:
Aspx page:
<asp:PlaceHolder ID="ph" runat="server"></asp:PlaceHolder>
Code-behind:
var anchor = new HtmlGenericControl("a") { InnerText = "Previous" + " " + PageSize) };
anchor.Attributes["href"] = "?pg=" + (CurrentPage - 1);
anchor.Attributes["class"] = "prev button";
ph.Controls.Clear();
ph.Controls.Add(anchor);
As you can see by the amount of code needed for what is essentially supposed to be be a simple and light-weight anchor, it's not the most optimal solution. I know I could use a Literal but I figured this was cleaner as I'm adding more than one anchor.
View 4 Replies
Mar 17, 2014
The control works fine with hard coded file name.
However, I need to pass on an mp3 filename dynamically with code.
How can I do that? I use vb.net ...
View 1 Replies
Mar 6, 2010
Sql Server 2008 introduced a number of new data types. One of those types is Date. I have been trying to find the C# equivalent of the Date data type. Before I start using the Date data type I have a few questions. Am I correct that I still need to use the DateTime Data type in C# when mapping data to and from Sql Server? I am using Linq to Sql. Are there any conversion issues that I need to be aware of when mapping the Sql Server Date into and out of a C# DateTime property?
View 2 Replies
Sep 9, 2010
I have three tables.
CustomProfile
UserID (pk)
DisplayName
CompanyID
Teams
TeamRecordID (Pk)
TeamID
CompanyID
EmployeesInTeams
UserID
TeamID
I want to assign employees to teams via a gridview control with a templated checkbox.
I have a dropdownlist control to select the TeamID.
I am having problems with the select statement.
The gridview needs to select employees that are not assigned to any teams as well as assigned to other teams. An employee can be assigned to many teams.
What I have been trying is:
cp.UserID, cp.DisplayName, et.TeamIntID, cp.CompanyID
View 32 Replies
May 10, 2010
I have been searching for some information on how to import my xml file into a series of tables using a mapping file (schema).
View 2 Replies
Nov 3, 2010
I'm working on an ecommerce project that is missing 5,000 product pictures.
I am trying to assign all products without pictures into a category located on a mapping table.
I know an insert can be accomplished from one table (or subquery) to another but I only need to find the product IDs and insert them with default values into the category mapping table that has all non-null columns.
The following code is the farthest I can get without help (I'm not strong in SQL), it won't work because my subquery returns many rows while the SQL statement is designed to insert one - I don't know how to handle this...
[Code]....
Any help would be appreciated from those more experienced than I. BTW... there are no known search results for this type of solution - if there is even a solution.
View 2 Replies
Feb 7, 2011
See the following code. I'm uploading files, Yet i'm getting different results from difference browsers.
Firefox var path = "about.restaurant.jpg"
yet in ie6 path = "D:devxxxxxxxxxxxxxxxWebsiteimagesabout.restaurant.jpg"
foreach (string file in Request.Files)
[code]...
View 1 Replies
Sep 16, 2010
I am wanting to create a path somewhat like this: /Administration/News and have it forward to a News controller instead of it being the action.How would I go about this?
View 3 Replies
Feb 28, 2011
Iam new to ASP.NET and poking around my first ASP Web Application projects in .NET 4.0 I have problem, which I can't solve, and google searches does not bring any joy. So I would ask for and/or explanation of following problem:
Assume that I have set up following project structure:
default.aspx
[gfx] (dir)
[images]
picture.jpg
[css]
stylesheet.css
[Code]....
View 5 Replies
Jan 7, 2011
I have the following code, which generates insert queries
For Each f As String In Directory.GetFiles(d)
objSQLStringBuilder.Append("insert into table1 (full_path, file_name) values ('" & f.Replace("'", "''") & "', '" & f.Remove(0, Len(d) + 1).Replace("'", "''") & "');")
Next
However, the paths which it finds are formatted as follows c:program filesmicrosoft officewinword.exe I need to format the paths as follows file:///c:/program%20files/microosoft%20office/winword.exe. How can I modify the above code to do this?
View 5 Replies
Mar 4, 2011
What is the correct way to reference an image in ASP.NET for live deployment on IIS? The following works in dev and production:
<asp:ImageButton ID="ibnEdit" runat="server" OnClick="ibnEdit_Click" ImageUrl="~/App_Themes/Default/images/one.png" Visible="false" ToolTip="Edit" />
The following doesn't work in either: (why not?)
<img src="~/App_Themes/Default/images/two.gif" />
The following works in dev but not in production:
<img src="../App_Themes/Default/images/two.gif" />
View 2 Replies
Sep 30, 2010
This may be a dumb question, but I've got a DLL that I compile and reference locally in a web site project and everything runs just fine. When I deploy this solution to the test server, I get an "Object reference not set to an instance of an object." error and the stack trace displays the files with their paths that are causing the error. The thing is, the paths being displayed are the absolute path as they existed on my development machine. Here's the stack trace:.........................
View 3 Replies
Jul 22, 2010
I use ASP.NET routing to rename the full paths of my URLs (ie. /page1/page2/file.aspx would just become /file.aspx). This doesn't work with web.config authorization, because that uses physical path/folder names.
View 1 Replies
Mar 14, 2011
We have a multilingual site, or culture-sensitive, and some of the static content now needs to be targeted; for this I'm using themes as it seems the easiest way to achieve what I want, but I can't for the life of me get the images to pick up.I'm setting the theme in code-behind, and thought at first that maybe this was the issue, but on checking up it looks like I'm doing the right thing (setting on Pre-Init).
I expect to be able to reference images using relative paths where App_Themes/ThemeName/ is automatically resolved, such as:
<asp:Image runat="server" ImageUrl="imagesimage.jpg"/>
For whatever reason, however, the image isn't being pulled through at all.This is the code we have in place for setting the theme (the only really relevant part, I'm sure, being the Theme = CurrentSite.CultureName, which is applied successfully):
Private Sub SetTheme()
Dim themesPath = Server.MapPath("~/App_Themes")
If Directory.Exists(themesPath) Then[code]...
In the above code, CurrentSite.CultureName would be a language culture name (for example, en-gb, or nn-no) that does have an existing corresponding theme folder containing all required resources.Pages do have EnableTheming set to True. Also, I have tried removing the theme-setting code and applying the theme in the page using Theme="en-gb" to no avail.
Is there anything immediately evident as to why the URLs aren't resolved?
View 1 Replies
Jul 14, 2010
Is it possible to scan all .aspx files in a web-site directory ? Suppose that , i've a home page like home.aspx, and many other pages.
How can i list all other pages with hyperlinks ?
View 3 Replies
Jan 24, 2013
I have implement url routing on my website project in vs 2010 and IIS 7.
But after implemented I have facing issue where images and css some times load and some not.
View 1 Replies
Jan 21, 2010
I'm developing an ASP.NET Website locally using Web Developer Express Edition and publish my site via ftp to the remote host. Problem: Locally I'm using path settings to xml files etc. different from the remote paths. So each time before I publish my site I have to set the remote paths explicitely commenting out the specific lines of code.
Sample:
if(local) {
XDocument loaded =
XDocument.Load(@"<localpath>jobitemssample_" + companyId +
".xml");
else{
XDocument loaded =
XDocument.Load(@"<remotepath>datajobitemssample_" + companyId + ".xml");
}
How can I achieve an automatic setting mechanism on deployment. How do I know how to set local?
View 2 Replies
Jul 20, 2010
I have a sitemap, and i'm using nested repeaters to display the parent and child nodes for my breadcrumbs.I have 3 pages: Home, Hub, and Search.Each of these pages can navigate to each other. In other words:
Home> Hub
Home> Search
Home> Hub > Search
Home> Search > Hub
Home > Default
The most common path would be "Home > Hub" and Home > Search > HubHowever, I can't seem to figure out how to show this on my breadcrumbs, since you can't have multiple ULR's in the Sitemap. Right now, you can only go "Home > Hub". If you go from "Search" to "Hub...it should show "Home > Search > Hub" in the breadcrumbs.
View 5 Replies
Dec 20, 2010
How to specify multiple paths in one location element in web.config:, a
<location path="Images">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
We would like to add styles and images to location, e.g. location path="images, styles". Is it possible to put multiple paths in location element (and how)?
View 2 Replies
Jan 27, 2011
I have a website, lets call it mywebsite.com. I also have a blog at mywebsite.com/blog. I have made a URL rewrite rule so it can be accessed from blog.mywebsite.com. The issue is that all my root relative paths (~/) do not work when viewing the blog from blog.mywebsite.com. Ok, say if there is a link on my blog that goes to a blog post that is at ~/blog/post.aspx?id=1. It will then go to blog.mywebsite.com/blog/post.aspx?id=1 which is actually, mywebsite.com/blog/blog/post.aspx?id=1 and that does not exist.
View 3 Replies
Sep 16, 2010
I am working on a localization project, some of the localized text are in graphics, some of the example graphics paths:
/en/images
/es/images
/fr/images
My web forms use <asp:image> controls and <img> tags (runat = sever) to point to graphics in /en/images. I need to a function to loop through all image control and point them to different paths based on the locale set at runt time. Which event should I override and how do I write it?
All my web pages inherit from a base page, I don't know if that makes differences.
View 5 Replies
Sep 28, 2010
How do I deal with master pages and relative paths especially when dealing with sub-folders?
View 1 Replies
Jan 9, 2011
I am looking to write a stream filer in a http module that anyalyze the output html of a page, search through the pages html for any images within the page, check if the source of the image has a full path or relative path. If its a relative path, alter it to have a full path. Anyone ever write anything anything like this? Looking for some examples of such?
View 1 Replies