I deployed mvc-3 application on windows azure. In my application i am uploading the file an save it in the App_Data/DownloadedTemplates folder.
var path = Server.MapPath("~App_Data/DownloadedTemplates");
my application is running on staging environment currently. When i uploaded file , it shows me an exception in the browser :
Could not find a part of the path 'F:\sitesroot\0\App_Data\DownloadedTemplates\B.htm_2c77cdfd-c597-4234-bd1e-29ca0a9b8d0e.htm'.
I am using Server.MapPath to locate the path of App_Data on the server, now why this exception ?. Can anybody tell me the problem ?
You shouldn't be doing this in a Windows Azure application. In Windows Azure you should use LocalResources (reserved space on a dedicated disk) for saving temp files on the disk, this is the only place where you should store data.
Here is an example of how you would access such a LocalResource (name and size can be configured in the VS project):
LocalResource localResource = RoleEnvironment.GetLocalResource("DownloadedTemplates");
Don't forget that data in LocalResources might disappear (when the machine crashes for example). If you really want to persist your data, you should be using Windows Azure Blob Storage.
Related
So I'm trying to make a program that uses an excel file to get some data.
I'm trying to make it so i can update data while the application is running, but i have no clue on how to get the file from onedrive.
The application is running c# .net 6. Reading the data from a local path is no issue.
I want to know if there is a better way than onedrive, or how i would read the excel data.
Scenario: The application will run on a remote server. I need to update the excel file from my own pc. I would rather have the file locally and have onedrive automatically syncing it on the machine, than having to remote desktop to the server.
UPDATE:
I've now tried troubleshooting and it seems like the path can't be found. I've written the path in console to see if it uses the correct path on the server as well, when using path in file explorer, i go directly to the file.
So having this issue i was not thinking about the posibility of not having the rights to access the file.
To fix the issue i had to go into application pools and then edit the application pool i was using, for that service, to a user having rights to the folder it tried to access.
Please suggest the best way to I copy data from Azure File storage to local machines every 2 hours (periodically). Can we write a C# exe to do that and deploy it on the PC?
Write a desktop application in any language with the SDK support of Azure File Storage. Within that application, create a timer to do your download through the API.
If the there are configurable settings or user interactions needed, I'd say go for a desktop application.
Otherwise, and if your clients are windows PCs, best way would be to write a windows service that does the job.
You perhaps could use Azure Logic Apps - if you set a job to run periodically and copy files from File Storage to OneDrive, for example, then OneDrive would replicate your files onto a on-premise server.
Currently trying to save a file to a folder on a network location.
network//location//folder/save-here
The WebAPI is connected though azure/VPN /Entity Framework, however I need to save the file on the protected network location, not just a record in the database.
I've started trying to use a Hybrid Connection, however I'm not sure it will help solve this issue.
What is the best way to achieve saving a file to a folder on a network location from a Web API/Azure?
Unfortunately, in the Application Service Plan you cannot mount a file share.
If you were using Azure's file share from Azure Storage, you could just save the file using the API. However, since you are trying to save to an on-prem file share, you might need to set up some kind of service (possibly another API) running on-prem than you would call and it would be able to save the file for you.
I am using c# asp.net mvc 3 and entity framework to upload the file to the network drive mapped as Z drive. I have following c# code for determining file path:
var path = Path.Combine(Z:/upload/catone/", fileName);
aries.SaveAs(path);
I am using window server 2008 and IIS 7. I have also check Security of upload folder of network drive and have acess full control for EVERYONE user. If I changed file path to local drive, it works fine. But it shows following error while uploading to network drive (Z:/).
Could not find a part of the path
'Z:\upload\catone\_2013011504265221N_todaily.wav'.
Your code is running under IIS and thus is run with access privileges of the IIS user account which may not have access to that network drive.
You can try runnning the app pool under your identity for instance, to rule this issue out, or give full access to the group IIS_IUSRS to that folder.
First of all save the file in local machine ,
than after use file.copy(Source, Destination, true) method to save file in network drive.
try that it is helpful for you
When I ran the app in VS2010, it correctly downloads the file to C:\Users\{UserName}\Downloads folder using the below code.
string userDownloadFolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Downloads\\";
But when I host the app in IIS, it goes to C:\Users\.NET 4.0 App Pool\Downloads\
Yes the app pool is in .NET 4.0 App Pool.
How I can get the logged in user's downloads folder by hosting the app in IIS?
ASP.NET runs at the server, and anything you do in code-behind refers to the server. When you were testing it locally your machine was acting as the server, which is why you were able to get the files to download to the correct location.
You can't tell the client where to download a file. Access to the client's file system is intentionally restricted for security purposes. Can you imagine the security risks if a website could gain insight about your file system and choose where to download files?