I'm trying to read from a text file that contains some data in my bot. I have the file in my Visual Studio solution and the bot is able to read the data fine when I am using the Emulator.
However, when I publish, it says that the file doesn't exist (IO.DirectoryNotFoundException) and gives this path as the path it's looking at (my file is in the Data\Holidays folder in Visual Studio):
D:\home\site\wwwroot\Data\Holidays\Holidays.txt
Is the path different when it's published? Do I have to upload the text file to Azure manually?
Thanks!
Do you include the file as a part of your project? (after build, check your bin folder). If not, then please include your file.
For more details you may try these links
1)Entity Framework - How to get relative file path in seed method
2)ASP.NET Web application file path (Publish on Azure)
Related
I just started to learn C#, and currently trying to create a simple program that read 1 row of data from SQLite database.
I've successfully created the program, but i still have to refer to the .db file with full address like :
SQLiteConnection("Data Source=C:/Users/../SQLiteStudio/dbs/mk_ii.db; Version=3;")
But this way, the .db won't be included when i create an installer. I want to make it something like when i add an image to my Solution Explorer, i can use short address like :
res/img/logo.png --i also have copy of .db file in res/ folder
So, is there any way to include the .db file to my project? I've tried to read current directory and using |DataDirectory|, but all of those referred to the .exe file's active folder, and didn't work when i debugging since when debugging the .exe file have different directory than the project directory.
For a note, i'm using VS Community 2015 and System.Data.SQLite. Also i've tried added the .db file to Solution Explorer, but i can't seem to access through it.
Include your database file in your project. Set the type to Content, that will make sure the file is copied to your output directory. Use relative path in connection string.
In the first installation in my WPF application I checked if the SQL database for my application exist or not, If not the application restore it from .bak SQL file.
When I publish my application I can't attach (Embed) the .bak file.
How can I do that ?
Thanks in advance
Abdusalam
Well .. I got the solution :
One good way of doing this is:
Create a folder under the app in VS name e.g. "datafiles"
Add all files to that folder using Add as link in the dialog box after selecting Add existing item on the folder
Mark all files as Copy if newer (Copy to output directory property)
Make sure the build action is content
--> when you publish the files will be put in that folder and be a part of the application installation
Good luck!
Source
I'm trying to publish a project which needs some data which is stored in a .txt file.
The file is currently located in bin\Debug.
The Path for the Streamreader is relative using Applicaton.StartupPath.
I added the .txt file to the solution explorer, but somehow i get a bad path error message every time i try to start the published setup.
How do I publish my Project with the needed .txt File?
You have various ways of achieving this.
The txt file included in the solution file will have a property called Build Action. Change it to Content and it should be published with your deployments.
You can add it to your resources, but then you will need to access it differently.
Add it to your installation package
I am testing publishing a program with Visual studio 2012, but when I install said program I get errors because a database file I need is missing.
I have a small sqlite file I have included as content and I have set it to copy to output directory. and everything works if I am debugging it. but when i publish the file isn't there anymore.
I guess the problem has two answers I can see, I either need to figure out how to have the file be put there when it is installed or on startup of the program look for the file and if it doesn't exist, copy it to there from a resource?
any clues would be appreciated!
thanks!
The following link should show how to include files for publishing: http://msdn.microsoft.com/en-us/library/kzy0fky2(v=vs.80).aspx
Specifically:
Files with the Build Action property set to Content are designated as application files and will be marked as included by default; they can be included, excluded, or marked as data files. The exceptions are:
•Data files such as SQL Database (.mdf and .mdb) files and XML files will be marked as data files by default.
If you change the handling from Data File (Auto) to Include, Visual Studio should output it correctly.
I have project 1 and Project 2. If using File Upload feature in some Project1's code file I want to save the uploaded files in Project 2's folder. What should be the save path??
Like I gave the physical address as D://Project2/images/products/
but it says, I cant give physical path and that only virtual path will be accepted. What should be my saving path?
Please help me out. Thanks.
#Peyman
how exactly wil I refer to this folder in my c# code?
# Peyman
I tried your solution..its creating the Upload folder in c:/inetpub or something and giving this error when I am running upload code "C:\inetpub\wwwroot\Upload\images\products\Product1\"
You can create virtual folder in your IIS and point to the specific folder in second project. then when you want to upload any file save in Virtual Folder Url.