Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to access c# codes from "higher" folder?

Posted on 2004-09-30
13
Medium Priority
?
184 Views
Last Modified: 2010-04-15
Hi all.

I have a project which is running in a sub folder of the server (I had to do this as I have to add a subfolder, when I start a new project in Visual Studio).
So my current project looks like this:

http://www.mydomain.com/
http://www.mydomain.com/cs/
http://www.mydomain.com/cs/forum/forum.aspx
http://www.mydomain.com/cs/forum/helperForum.cs

helperForum.cs has only the namespace "cs", not "cs.forum".

Now I need to have an aspx here:
http://www.mydomain.com/a/whatever.aspx

This "whatever.aspx" has to call the helperForum . If I try it like this:

<%= cs.helperForum.getSomething() %>

i get the error:
" The type or namespace name 'cs' could not be found..."

What do I have to do, to be able to access all codes from my "cs" project (not CounterStrike! ;)) in any other location on my server (even root!).

Thank you.
0
Comment
Question by:Smoerble
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
13 Comments
 
LVL 9

Expert Comment

by:Thalox
ID: 12188445

Hi,

by "project" do you mean your project (solution in vs) or real vs- project?

if this is only one project then there should be no problem accessing other cs files (in this project)

if there are more projects you will have to include references to them in your current project.


and another thing:
is "cs" your toplevel-namespace? If you want to call something in your aspx - page, you need to specify the whole namespace. the aspx-page ignores any "using" declarations in the codebehind.


hope this helps,

Thalox
0
 

Author Comment

by:Smoerble
ID: 12188478
Ok, I explain more detailed:

I have a webserver running since some years.
Now I added some c# code. For this, I installed VisualStudio and started a new project in VS. When you do this,. you have to give it a folder name and you can't give it the root directly.
So I named mine "cs".

Every class I add to the project contains these lines:
---
using System;
...
namespace cs
{
---

What works fine:
http://www.mydomain.com/cs/forum/forum.aspx 
calls a helper function from
http://www.mydomain.com/cs/forum/helperForum.cs
by sinply using helperForum.whatever(). No issues here.

What does NOT work:
http://www.mydomain.com/a/
should call helperForum.whatever(). This does not work, even if I use
cs.helperForum.whatever()

Oh, important:
the cs.dll and cs.pdb files are located here:
http://www.mydomain.com/bin/

Did this clearify my problem?
0
 
LVL 9

Expert Comment

by:Thalox
ID: 12188553

It does not matter where the "original" cs.dll is located.
vs will copy all needed dlls in the right directory.

where does your "a" come from?
is this a new project?

as I understand you have the following:

project "cs" with helperfunctions
project "a" which needs to call a helper function

is this right?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Smoerble
ID: 12188947
"a" is not a VS project, it's just a folder with a plain *.aspx in it.
But yes, I want to access my "/cs"-helper functions form folder "/a".
0
 
LVL 9

Expert Comment

by:Thalox
ID: 12189088
hm, nice problem ;)

the root of your app is http://www.mydomain.com/cs, right?
or http://www.mydomain.com ?
where is your web.config?

and if it is /cs, how did you create the a folder and put the file in it?


are you able to access  your cs - functions  from the codebehind in folder a?
0
 

Author Comment

by:Smoerble
ID: 12189297
the root of my app is /cs .
I wanted it to be "/" (root) but I could not figure out how to explain VisualStudio what I want ;).

web.config sits in "/" (root).

I could not get it working to access any of my codes in "/cs/" from "/a/". Exactly this is what I need :).
0
 
LVL 9

Assisted Solution

by:Thalox
Thalox earned 1600 total points
ID: 12189556

I think there went something wrong with your app.
the web.config must (I think) be in the root of your app and you also can only create / access files and folders within this root.

And I could create my app in the root of my server (http://localhost)
(but this is not good practice, it's better to create a new directory and set a redirection to this dir in your web-root)

I think you should create a new web-app (http://localhost, or whatever) and copy your current project-files (*.cs, ...) into this.
http://www.mydomain.com/Myapp/                 <- root
http://www.mydomain.com/Myapp/cs
http://www.mydomain.com/Myapp/a

and set a redirection in IIS from http://www.mydomain.com to http://www.mydomain.com/Myapp/

then you should be able to access everything in cs from a.


Thalox
0
 

Author Comment

by:Smoerble
ID: 12189592
I just learned, that there is "some way" to tell a project in VS to use sources from another project.
Did not know this, so I have to learn how to do this ;)
0
 
LVL 9

Accepted Solution

by:
Thalox earned 1600 total points
ID: 12189727

yes, just add a reference to your project.
right click on your project -> add Reference -> choose the dll / or Project (if in same solution) -> OK
0
 
LVL 8

Assisted Solution

by:tomvergote
tomvergote earned 400 total points
ID: 12189855
Add both projects to the same solution in visual studio, and in the "a" project reference the "cs" project.

presto
0
 

Author Comment

by:Smoerble
ID: 12436071
ok, after a lot of tests ;) I would like to go with the following approach:

make all code somewhere below
d:\www\cs\
so it would be something like:
d:\www\cs\forum
d:\www\cs\cms
etc.

For this I want to change my localhost from d:\www\ to d:\www\cs\

So I go to VisualStudio and start a new project and call it "www".
When creating/opening, it stops with the following error:
Unable to open Web project "www". The Web "www" located on the server "http://localhost/" does not exist.

So... to finally solve this issue, how do I make a new project directly on my localhost folder instead of localhost/anyProjectName ?
0
 
LVL 9

Assisted Solution

by:Thalox
Thalox earned 1600 total points
ID: 12482114

I think you can't create a project under localhost (my vs automatically puts an application name after localhost/ and so a project under loaclhost would be a project without name...)
But you can create a project under localhost/project and do your programming and then for "public" access you could create a new Web Site in your IIS (with other port then 80) and set its Home directory to your project folder (D:\www\cs).
then you should be able to access your application with
http://localhost:<OTHER_PORT>/

If you do not want this port in your "final" url, just change the port of your default website, so your new can use 80
(I'm not sure, what will happen if both use the same port...)

And I think you can somehow use IIS Server extensions to add another url to an web-application (but do not know how ...)

Thalox
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question