Location of user files with a ClickOnce application - winforms

I have a WinForms app that I am trying to deploy with ClickOnce. It consists of an executable and a dependent dll, plus a bunch of loose xml files in a folder called "Map". The xml files all seem to be present and correct in the generated clickonce package and are all included in the .manifest file.
However, when I install and run, using the following code gives me a directory not found exception:
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
string mapPath = Path.Combine(appPath, "Maps");
foreach (string xmlFile in Directory.GetFiles(mapPath, "*.xml"))
when I look in "appPath" (which is C:\Users\Mark\AppData\Local\Apps\2.0\0H6ZLXXN.30V\3TNO49OJ.8JH\midi..tion_5194807c0e95e913_0000.0004_b9d52c73fd4d58ad\), there is the app executable and dll, but the Maps folder is not there.
What am I doing wrong? Is this the correct way to be bundling extra files with my application? I would actually like the Maps folder to be somewhere the user can easily access and add their own files to anyway.

ok, I eventually found a code snippet that helped me out. The xml files were already being put into the ClickOnce "data directory" (this can be configured using the "application files" button on the publish tab of the project settings dialog. Then you can get at the data directory as follows:
private string GetDataDirectory()
{
if (ApplicationDeployment.IsNetworkDeployed)
{
return ApplicationDeployment.CurrentDeployment.DataDirectory;
}
else
{
return Application.StartupPath;
}
}

Related

How to access files uploaded to the public folder in Next.js?

I have a project in Next.js. I have that upload files and share that in public URL to this project.
With npm run dev first I uploaded files to public folder and it worked fine, but when I change to npm run start and upload files, the files upload to public folder but with URL http://mydomain/fileuploaded.jpg it did not show, is rare but it's there.
I searched on the Internet but I didn't find a solution for this problem.
From Next.js documentation:
Only assets that are in the public directory at build time will be served by Next.js. Files added at runtime won't be available.
You'll have to persist the uploaded files somewhere else if you want to have access to them in the app at run time.
Alternatively, you could setup your own custom server in Next.js, which would give you more control to serve static files/assets.
You can also achieve something similar using API routes instead. See Next.js serving static files that are not included in the build or source code for details.
a bit late but if someone need the same.
If your goal is to upload and get picture from your next server, you can instead of using the Next router, getting the image by yourself by create a route /api/images/[id] where [id] is your file name and you manually with fs send the picture back.
something like:
const file = await fs.readFile(`./uploads/image.png`)
console.log(file)
res.setHeader('Content-Type', 'image/png')
res.send(file)
Try and use nginx or another webserver to serve the public directory. That way it will serve newly added files without having to write extra code to serve files in nextjs.
server {
/images/ {
root /var/www/site/public
}
}

laravel 5.4 image 404 error

I am uploading images to my applications storage/app/public/avatars directory. The files are uploading and are there in this folder - i have checked it. And loading the page shows the image as long as i am in my local pc. Then i moved the project to a shared hosting. Since then the images are not loading. From chrome console network tab i can see for the images laravel is throwing 404 error.
Here is what i have tried:
On the remote machine i recreated the symbolic link in my public folder as storage that is pointing to the storage/app/public folder.
Tried to copy and paste the image src directly into the browser - getting NotFoundException in RouteCollection.php
Cleared views, cache, config cache
Spent 5 hours trying to figure it out. Works fine on local pc. Just not on the shared hosting.
Desperately seeking help :(
After a bad night sleep of 4 hours i started again and found the problem. Very novice mistake, but can be ver hard to locate.
Here is what it is. I uploaded my laravel project folder to a shared hosting. Say my project name is myproject. This folder is at the same level as the public_html folder. Then i copied the contents of the myproject/public folder to the public_html folder.
As you know, you are supposed to create the symbolic link inside your public directory and the link should point to the storage/app/public directory (if you are using the public disk driver for your file storage). I did create the symbolic link inside the public folder, but at the wrong public folder. Since i copied the contents of public folder to the public_html folder, i should have created the symbolic link inside the public_html folder, not inside myproject/public folder!!
----public_html
---css
---js
---(other files etc. etc)
---storage <= this is where the symbolic link should be
----myproject
---public
---css
---js
---(other files etc. etc)
---storage <= not here!!
Very stupid of me.
btw, below is a tutorial of how to transfer a local laravel project to a shared hosting:
guide to deploy laravel 5 app on shared hosting

In which folder to store text files in Google App Engine project and how to retrive them?

I want to store text on google app engine. In which folder do I need to store them, and how to get the path of the file ?
I have tried storing them in WEB-INF folder and I have tried following path to retrive file:
FILE_PATH="/RESTful Jersey App/war/WEB-INF/abc.txt"
If you want to access this file anywhere, you put it in the /war folder or any subfolder within it. To retrieve it:
FILE_PATH="abc.txt"
If you want to access this file internally in your server code, you put it in the WEB-INF folder. Then you use:
FILE_PATH="/WEB-INF/abc.txt"
As stated above you can place it anywhere inside your war folder if you wish to make it publicly accessible, if you need that file to be accessible only to your app (eg a PK12 secret file) you need to place it within the WEB-INF folder.
I order to actually retrieve it you need to get the real path from your current ServletContext eg:
ServletContext context =//your servlet context (either injected into and endpoint or gotten in an actual Servlet.
String path = context.getRealPath("<path starting form the base WAR dir>");
try {
FileInputStream input = new FileInputStream(path);
template = CharStreams.toString(new InputStreamReader(input, "UTF-8"));
} catch (Exception e) {
e.printStackTrace();
}

Retrieve file relative to play application path

I created a Play! app and deployed it under TomCat. This works well. The only problem is the management of a properties file, currently in the conf folder right next to application.conf. But as soons as the client replaces the war file the custom properties are overwritten with the default values, resulting in errors.
Now I want to introduce a seperate properties file placed inside the webapps folder. This way I will be sure my clients will not overwrite the file 'accidentally'.
So the structure would be:
TomCat webapps:
myPlayApp
PlayConfig <-- here I want to place the config file
So I would like to retrieve the properties file by something like:
getFile("../PlayConfig/app.properties");
This obvious does not work, but I do not know how to achieve this?
I thought retrieving it by tomcat http url but the portnumber my vary, so this would also not work, I guess...
UPDATE 2012-01-25:
Actually when using the following code:
Play.applicationPath.getPath();
I get the absolute path when running the project outside tomcat (so not inside war file!)
When I deploy the same project in a TomCat server I get the following output:
W:\tomcat-5.5\webapps\MyTestProject\WEB-INF\application.
From this point on I can indeed use a relative path.
I think that when deployed in a Servlet container, play uses the /WEB-INF/application as base directory.
Try changing the path relative to this folder.

ubercart file download setting problem

Hi I am using drupal 6.x and ubercart 2.x. I trie dto create a product,but when it comes to add the file download feature I am getting some issue. I put a folder called downloads in the drupal folder and one file inside the download folder.then I gave the path as "drupal/downloads but it is telling that drupal/downloads is not a valid file or directory"
I tied the following file paths too
1.www.mysite.com/drupal/downloads/faq.ods
2.drupal/downloads/faq.ods
3.drupal/faq.ods(after putting faq.ods in the drupal folder.
But still I am getting the same message. Plesae some body help me
It is looking for a path rather than a URL. You should probably aim to find out from your hosting company what the absolute path for your webroot is (e.g. www.mysite.com may actually be on disk as /users/mysite.com/httpdocs) and put in that followed by /drupal/downloads

Resources