I am just starting to learn ASP.NET (C#) and I am struggling with a tutorial I am working on.
I have my App_Code Folder and within it, I have a folder called DataAccessStuff. Within this folder are a bunch of .cs files I will be using for the data layer of things.
The problem is, Visual Studio is unable to detect the location of these .cs files and gives me the error:
"The type name "DataAccessStuff does not exist in the type 'System.Web.UI.WebControls.Content"
I have no idea how to get it to recognize. I simply copied the project file from the textbook CD onto my computer as it said. I have attached images showing the precise tree layout of the project as well as the code I am using. If anyone can please help a beginner out, it would be appreciated.
Thanks!
Inside one of the .cs files
The namespace is probably
Content.DataAccessStuff
based on the root name of your project. However, if you simply double click the file in DataAccessStuff that you want to access, it will give you the namespace of the file.
EDIT: Since this is a Web Site Project, not a Web Application Project, namespacing is by default not explicit unless added.
Make sure anything referencing something belonging to the folder Content.DataAccessStuff has a
using Content.DataAccessStuff;
at the top of the class with the rest of your using statements.
The following article does an excellent job highlighting some of the key differences between Web Site Projects and Web Application Projects.
http://msdn.microsoft.com/en-us/library/dd547590.aspx
Check the namespace provided in all the class (.cs files) of 'DataAccessStuff' folder.
It should be 'Content.DataAccessStuff'.
write using lab6.DataAccessStuff instead of Content.
Related
While using Java in Eclipse IDE, one can add a folder to the "Build Path" using the "Add Class Folder" option in the "Libraries" tab, which allows the resources in that folder to get compiled inside the application's jar file, rather than outside or not at all.
.
With this, one can get the resources inside the folder as a URL via the Class.getResource(String name)method. I am already informed about C#'s equivalent: Assembly.GetManifestResourceStream(string name) or Assembly.GetManifestResourceInfo(string resourceName) methods, but I am not aware of C#'s "Build Path" equivalence in Visual Studio (I am using 2019, if you wished to know). Could somebody please explain how I would accomplish Java's build path resource folder in C#?
(Note that I am looking to create a resource folder where anything put inside the folder would be considered an application resource. I am not looking for a way to add one or more resource files individually.)
Any replies would be greatly appreciated! :)
After a little research, I had found a solution for this problem. There are in fact two possible solutions to this issue.
.NET Core Solution
The first involves editing the .csproj file of your C# project. This solution is only available in .Net Core.
You can add this code snippet to your file and change the {PATH_TO_RESOUCE_FOLDER_HERE} folder to your desired folder.
<ItemGroup>
<EmbeddedResource Include="{PATH_TO_RESOUCE_FOLDER_HERE}\**" />
</ItemGroup>
Now any item placed in that folder will be considered an embedded resource Assembly.GetManifestResourceStream(string name) method.
Regular .NET Solution
The second method involves using a .resx file to encapsulate all of your resources
In Visual Studio 2019, you can create a .resx file by right clicking on the location in your project where you wish to add the file to, and navigating to Add > New Item (you may also press Ctrl+Shift+A). You can now navigate to the item that quotes "Resources File" and select it. You can now use this GUI to insert your resources (for a deeper explanation, click on this or this link. For use cases, see this MSDN).
The "Resources File" option
Note that this solution will also work in .NET Core.
I hope this answer helped you as much as it did me! :)
You just create a folder and name it as you like it, say 'Resources'. Add any file you want in there to be treated as a resource by your application.
Then navigate to the properties of every resource file (you can press F4) and in the menu you can choose what you want the compiler do with that file (Compile Action is the option name if I remember well). There you select the type as a resource, the namespace (your Build Path), and whether you like the file to be copied every time you compile your application, and so on.
It's a little bit complicated.I got a .net class library project form someone else and added it in my solution referenced by a asp.net mvc project. For some reason I changed the project name form "abc" to "xyz" and also Assembly name, Default namespace name in project properties page. I could build the solution and get the xyz.dll in the bin folder.
The problem is I can't run the web application because of the error "Compiler Error Message: CS0433:". I looked into the folder "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\" and found out the abc.dll still there and I checked the file detail information on properties page. The file description and product name are the same xyz, but the original filename is still abc.dll. I really don't know what's going on here.
I wish some could help me out,Thanks in advance.
You have to delete abc.dll from the root directory and then recheck it. Because IIS configure with this file and after changing it will not rebuild with this files as well.
Did you rename it in a file explorer or using Visual studio? Check the .csproj file and the .sln file and make sure all references in there reflect the new names. Also, check your dependencies and references to make sure they point at the new dll, and not the old one
You probably have figure it out but for other peoples who might search for the solution.
Right click on your solution or project file -> Click on properties -> And then there is first tab with name application Click on that. You will find two text box one for Assembly Name (Change this to xyz).
see attached image.properties dialogue box
We are working on a website project which contains around 1130 pages. After compilation, all the .aspx.cs files are converted into AppCode DLLs that has random names.
Whenever there are any changes in single .aspx.cs file[like a hotfix], we have to recompile and deploy the entire project on the application host.
We want to update only those files that have been changed and not the entire package.
One of a solution we are aware is that, converting Website to Web application; but we cannot implement that change at this stage of the project.
Is there any other way to find an efficient solution for this?
Yup. Talking in Visual Studio 2010:
While publishing the website, Select the option: 'Use Fixed naming and single page assemblies', Also select 'Allow this precompiled site to be updateable'.
After website is published. Go to the published folder. Open any aspx page (not the dll or .cs).. Note the dll name in page attribute under inherits attribute. Than using ftp or any other way to upload, copy or upload tht dll under bin to your website.
Also, you can create a doc or txt file to list all Dll names with respective paths to your file to easily know which dll to upload next time if there is any change.
Hope it helps.
We are moving from SourceSafe to Subversion as our source control provider... All is going well so far except I can figure out how you "share" a file between more than one project. In sourcesafe you made a link to the file and then added it to your project, then source safe knew that the file was really just one file. How do you do the equivalent with Subversion?
You can add a file as a link within Visual Studio directly.
Doing this means you don't have to worry about how your source control will manage things, so long as the referenced file in in source control - the link is managed by VS.
You're looking to share a CS (as in a code file) between 2 projects? From an design aspect, why not extrapolate that file into it's own project and then reference that project from the other projects.
I am using a SharedAssemblyInfo file which seems to be a 'standard' technique:
http://blogs.msdn.com/jjameson/archive/2009/04/03/shared-assembly-info-in-visual-studio-projects.aspx
I put the SharedAssemblyInfo.cs file into my web application because with web site projects I cannnot 'add files as a link'.
But now I need to add a second web project to the solution and obviously the SharedAssemblyInfo file cannot be within both projects.
How do I get round this problem without having duplicate SharedAssemblyInfo files?
One way to solve this problem from within a web site as opposed to a web project is via your source control provider.
If you are using Visual Source Safe you can "share" the file to both projects (folders) and not branch. If you are using subversion 1.6 you can use a single file "externals" property. See this page for info.
In the case of Team Foundation Server, you can look at this codeplex article. I don't have any experience with TFS, but I think in the case of a SharedAssembly.cs the branch and merge solution would work fine.
This means you will have to check the file in in one location and check it out in the other location for the change to take effect. However, have the AssemblyInfo out of sync during the development process probably won't break anything.
Is it a web site or a a web project? With a web project the linked file should work fine... although personally I'd rather keep them separate and update them through my build script.