asp.net imageurl uses physical path for testing - webforms

I know that we can't use physical path when the webpage is deployed.
But here is my problem: I'm developing an Application for C# winform and Asp.net webform, the Data folder for the app is huge and I need to put that folder separately from the projects' folders cause it would be convenient to backup my projects to Google drive. The C# winform is easy to link the physical path, but the asp.net webform forces me to put the Data folder inside the project.
My current solution is: putting the Data folder inside the asp.net webform project and link that folder to the C# winform. But it wouldn't be convenient to backup the webform.
But is there any way I can use physical path with asp.net webform just for testing?
Thanks for reading.

You can put the folder external to web app folder, then place the path in Web.Config Under AppSettings as
<appSettings>
<add name="Data_Folder_Path" value="C:\Path\to\Data\Folder" />
</appSettings>
Then in code behind or elsewheere you need the data path you use Configuration class to read the path value:
var dataFolderPath = System.Configuration.ConfigurationManager.AppSettings["Data_Folder_Path"]

You can make use of server.mappath as shown below
Server.MapPath("~/" + folderName + nameOfFile)
to get the location of the files.
You may save the names of the files on your database and retrieve them when needed.

Related

Building CMS on top of CodeIgniter

Is it possible to build a CMS on top of CodeIgniter where the CMS files is separate from customization files? What I mean is, like CodeIgniter by default comes with 2 main folder, application and system folder. So, all your own files is placed in application folder so that next time you can easily update CodeIgniter by overriding the system folder and everything will still working fine.
So, can I store my files at custom folder?
E.g.:
system folder - codeigniter
my_system folder - CMS
application folder - All customization on each individual projects
You may use CodeIgniter's native application "Package", you can find the doc here : http://ellislab.com/codeigniter/user-guide/libraries/loader.html
You can store your file where you want expect system folder as you written. best approach is make folder on root named public or you want and put your file.
system folder contains everything codeigniter needs. application folder contains your specific code - it defaults to showing the welcome page.
consider naming your system folder with the codeigniter version number and date
makes it easier when you are upgrading
and you can easily switch to different versions directly from the index.php page by editing the file path to the folders

app_code folder

Normally I only copy the dll files in the bin folder to update the website, when changing the codebehind.
I have made a change to a code file located in the app_code folder.
I have published the site and updated the bin folder with a lot of app_webxxx.dll files.
Now I get a parser error: Could not load the assembly 'App_Web_syn42ext
Is it possible to only update the dll files or do I need to update all aspx files everytime I make a change to get the website running ?
You need to do it as well, you need to update web pages as well, because if you will see when you publish the webpages in aspx page, on header tag, the reference of cs file upgrades itself.
So whenever you will publish there will be some random giud generated and will appended to file name, basically it reference to the name space.
So you will need to update web pages as well.

How to use ASP.NET MVC view precompilation with App_Code helpers?

I am trying to enable view compilation to have my ASP.NET MVC3 web site load faster. My web site is hosted on AppHarbor.
However, my views make use of MVC3 view helpers, defined in the App_Code folder.
When I try to load my web-site, I get:
"The directory '/App_Code/' is not allowed because the application is precompiled."
How can I stop the App_Code folder being deployed to the web-server, but still have the App_Code helpers pre-compiled?
I've tried changing the helpers to Content=None, but this leads to an AppHarbor build error because the helper files cannot be found during pre-compilation.
Old question, but I just got that problem, and the following procedure has worked for me:
Go to https://appharbor.com/your-application.
Click on Settings.
Click on Build | DISABLE PRECOMPILATION.
Force appharbor to do a rebuild/redeploy (by pushing a new commit to the repository).
I have just deleted my shared helpers and deleted the App_Code folder because of this problem. I have changed my project to use partial views instead .
According to this answer helpers must be in the App_Code folder but this won't work using AppHarbor.
I would say , don't use App_Code folder in web application. Please find more details ****here****

ASP.NET MVC3 project does not always publish all views/content

This is crazy, but I can't seem to get all my views/content/scripts published when I publish the site. This seems to happen, I believe, when the view or content is not directly referenced by my project, but used by another assembly in my project. So I might have:
ExternalAssembly.dll referenced (it gets published)
I'll need ExternalLogin.cshtml in my main project, under my views folder
ExternalLogin.cshtml doesn't get published
Right now I have a script that copies everything in the Views folder and dumps it to where I want it deployed, but VS should do this for me. What am I doing wrong?
When you click on one if these files what is the build action for it on the properties? Content....or? Set to content.
So your views files are in another project or folder outside your current project? Normally the files have to exist in the web site project, in it's views folder, not externally, and the build action should be set to Content and not to copy to the output folder. But there are some workarounds:
Duplicate them in to your site views folder and make sure they are marked content (as stated in another answer). One thing to note though is that you can add them as "Linked Files" in visual studio which actually allows them to exist in two places in the hierarchy without having to exist in two places on disk: http://support.microsoft.com/kb/306234
If you have control over the external library, you can compile them in as embedded resources or use Razor Generator or something similar and use a custom view engine to return them: How can I make ASP.NET MVC 3 use views (aspx, ascx) files from an external assembly in my website?
Manually put the copies in the .csproj build XML using the Copy task: http://msdn.microsoft.com/en-us/library/3e54c37h.aspx (Note that this will make it work in visual studio doing essentially what you are doing now, as it will then be part of the Visual Studio build if you add it to the AfterBuild target or something)

Mobile and desktop web app with codeigniter

I want to build two versions of my project for mobile and desktop.
Am working codeigniter 2.0.2, am looking for a way for the mobile and desktop versions of the project to share the same model, controllers, libraries, and helpers.
Also i have set up a sub-domain,m.xyz.com to point to folder called "m" on public_html folder,
i want the the mobile to be in the "m" folder and share resources with the desktop app residing in root so i dont create duplicate models, controllers etc.
CodeIgniter allows you to specify the folder that you are loading your views from. Since you want to reuse all of your application code, simply set up CodeIgniter so that it is loading mobile optimized views rather than the default (desktop) views.
Copy the root index.php file into the /m/ folder that you created.
Update the $system_path and $application_folder variables in /m/index.php with the correct paths.
Update the $view_folder variable in /m/index.php with the path to your view folder containing your mobile optimized views.
You mobile site will now mirror your desktop site - it will just be pulling in different views.
Note that the structure of your mobile views folder will need to mirror the structure of your default views folder.
EDIT: The $view_folder option will not be available until version 2.1. Here is the code if you wish to make the change yourself:
https://github.com/EllisLab/CodeIgniter/commit/8eef9c77512d4fad5357d3cbda83b89f844d7d16

Resources