Include .CS files in SharePoint solution package? - asp.net

I have a class file, where I store common methods used in several webparts. I'm asking now, how to include this file in .wsp package?

Class files will not be part of the solution directly, all the code files will be compiled and will be part of the project assembly.This dll will be part of the solution package and it will be placed in the GAC when the solution is deployed.
So there is no need for you to do anything additional.

Maybe you should create .dll which contains needed code and deploy it in seperate .wsp package.

Related

is File-List from a Folder (very simple)

Has anyone used this file-list from a folder? so called 'very simple'? we are looking for something to be used as a file storage/file repository module but this seems very complicated to set up for just a simple repository module.
I assume the folder would be any folder in your portal, not an ADAM folder.
In this case, you just need to write some standard C# using System.IO
Something like explained here: How to recursively list all the files in a directory in C#?

I cant import a dll into my project references C# .net Project

When I try to import a .dll (cplex1280) into my asp.net project references, I get an error saying Please make sure that the file is accessible, and that it is a valid assembly of COM componet.
The weird thing is that I can build my application even though this dll isn't referenced. For people who are familiar with CPLEX, I successfully included the ILOG.CPLEX.dll and ILOG.Concert.dll
Currently the directory for my project is setup as ProjFolder/Myproj. There is a folder ProjFolder/bin and a folder ProjFolder/myproj/bin where I included the cplex1280.dll file. There is also a copy of the cplex1280.dll in one of my Program Files folder. I tried to add a reference of this dll from each of these locations, but I keep getting the same error. When I looked up this issue, I saw two solutions that people recommended. Here is the post that I used for help.
One solution was trying to use
regsvr32 "foo.dll"
on the file. When I try this, I get an error saying
The module "cplex1280.dll" was loaded but the entry-point DllRegisterServer was not found. make sure that "cplex1280" is a valid DLL or OCX file and then try again.
The other thing I tried using was dll import
[DllImport("cplex1280.dll"]
I was a little confused by the Microsoft documentation. It doesn't specify what folder to put the dll in and usually there is a function definition after the import statement, but my program uses multiple functions from this dll.
If someone could explain this import method in more depth I would appreciate it.
As mentioned in the comments, cplex1280.dll is a Native DLL. It is a shared library for the CPLEX C Callable Library. For your .NET application, you should only add references to ILOG.CPLEX.dll and ILOG.Concert.dll (see the readmeWindows.html file in the directory where you installed CPLEX).
Dropping the CPLEX dll's into your windows/system32 directory is not recommended (see DLL Hell). Instead, when you deploy your application, you either need to make sure that the directory where cplex1280.dll is located is included in the PATH environment variable or that it lives in the same directory as your ASP.NET executables. This gives you more flexibility when you have to support different products that use different versions of CPLEX (or even multiple releases of the same product).

Is it possible to create a asp.net project from existing published files?

I am currently making changes to a site but only have access to the files on the FTP, Is it possible to build a project file and solution from these files so that i can code and then republish and deploy?
I have a list of files including a bin and App_Code file along with all the pages, How do i create a project from this?
Thanks in Advance.
as much i know only you can do in this scenario that add all the dlls to your new project and use some OOPs concepts (like overloading, overriding etc) to use all the functionality of existing project.
happy coding :D

Using PetaPoco T4 Generated file with a WSP (Web Site Project) project

In my ASP.NET 4.0 WSP project, I'm using PetaPoco for most of the data access. I've successfully generated the classes from the Database using the T4 templates. But, by default, when you set install PetaPoco, the Database.tt file is in /Models/Generated. So, the resulting database.cs file is placed there. But, since I'm not compiling the project (since it's WSP), I can't use the database classes. I know I could manually move the generated database.cs file into App_Code to use it or move the database.tt file into App_Code and that would cause it to generate the database.cs in App_Code but I wanted to make sure to use the best approach and I'm not finding relevent content on the interwebs.
So, how should I handle this?
Moving the Database.tt to the App_Code folder is the right thing to do. There no much more magic than that.

Moving Functionality to a class library project - what to do with the related resources?

I have a .net project whose part of the functionality is xls transformation.
I now want to move that functionality away from the main project to a separate class library project.
I have no problems moving classes and accessing them, but part of the resources that I wanted to move were xslt files that define the transformations. Those files were originally located in the special asp.net folder: App_Data and then accessed using Server.MapPath(~/App_Data/XSLT/anXsltFile.xslt)
I wanted to move those files to that separate library as well, but not sure how to approach it, and how to access those files within the class library.
Perhaps embed the xslt files inside your class library and stream read them as necessary to perform your transforms
http://support.microsoft.com/kb/319292
How to embed a text file in a .NET assembly?
http://blogs.msdn.com/b/alexdan/archive/2007/12/19/loading-embedded-resources-in-c-using-getmanifestresourcestream.aspx
http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/1d341eae-fed4-408c-8791-96e96a5fd99c/
I think a class library, unlike a web site project, should not have file resources. It should supply the functionality to the web site project which will host the files.
I personally consider both the class library and the xslt files to be resources of the web site. Lets say you want to use this same class in a different app or web site, with different xslt files.
It's bad for re-usability.
I suggest you to use string constant in Web.Config with the Server.MapPath path and use these to load the xslt files.
I hope it's helpful
if you mantain the xsltfiles on the app_data, you must use
httpcontext.current.server.mappath("...your path...")
if you move the xslt files to the assembly too, you must get the Assembly resource...

Resources