I am trying to get the IIS server directory path from another computer to download few files from there.
using codes like this..
using (var client = new WebClient())
{
client.DownloadFile("//serverpath", "a.exe");
}
I would like to download the files from the directory shown in the picture!
That is the server computer and I'll be putting some exe files in that directory .I would now like to download the files that i put in that directory to the client computer I'm am using. How should I put the serverpath?? Agent folder is an virtual directory.
If this is asp.net mvc there is direct support for this with FileResult, and Controller has a set of helpers:
In your action:
return File(filename, contentType);
Related
I'm working on a web app that runs Excel reports and I'm using an Excel template file that's saved on the server. It works fine when I run it locally but when I try to run the Excel report on the server I get an error saying access is denied to the template file that's saved in the same directory, but I can download the template file when I navigate to it in the browser.
I granted everyone full access to the file to see if that was the issue but I still get the error. What am I overlooking?
error errorId="05d6462e-8bb5-401d-85bc-cd4d9e36fc90" application="/LM/W3SVC/8/ROOT" host="USFLWCT0" type="System.UnauthorizedAccessException" message="Access to the path '\usflwct0\D$\SherlockRoot\Files\Volume_by_Week_Template.xlsx' is denied." source="mscorlib" detail="System.UnauthorizedAccessException: Access to the path '\usflwct0\D$\SherlockRoot\Files\Volume_by_Week_Template.xlsx' is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at
edit:
Here's the code used to open the file. The path is hardcoded for now
using (var template = System.IO.File.OpenRead(#"\\usflwct0\D$\SherlockRoot\Files\Volume_by_Week_Template.xlsx"))
You are using one of the admin shares that Windows creates for each drive, in this case the D$ share. They are only accessible by admin level users. You should share the folder you want directly, for example, share the D:\SherlockRoot\Files folder as SherlockFiles that was you can access the content like this \\usflwct0\SherlockFiles\Volume_by_Week_Template.xlsx or in code:
var file = #"\\usflwct0\SherlockFiles\Volume_by_Week_Template.xlsx"
using (var template = System.IO.File.OpenRead(file))
If you want the application to read the the template file, put it in the App_Data folder
I created a WinForms application that includes code to find the user's desktop and perform 3 tasks:
1. Create a folder
2. Read a .csv file
3. Output some data to a .csv file on the desktop.
I'm using the code below to find the user's desktop
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
I used the ClickOnce deployment to install the program to our network drive. The program installs successfully, but Whenever I have someone attempt to run the program from their terminal, they get an error message that states "The directory name is invalid" and it references my desktop and not the user's.
How should I change my code or the deployment method so it references the user's desktop?
If directory invalid try creating it
Try with this code
string filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string extension = ".log"; filePath += #"\Error Log\" + extension;
if (!Directory.Exists(filePath)) {
Directory.CreateDirectory(filePath);
}
I made the following change to my code and it worked as needed:
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
I am using Microsoft.SharePoint.Client to work with SharePoint 2013 files in asp.net MVC project. I am able to load file then execute the query but after loading, I have to checkout file. On checkout I am getting following error:
The URL is invalid. It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web.
I created this file via asp.net MVC project only. its fine while creating a file on Sharepoint via code. I also checked out that file from SharePoint directly. It's working fine there.
Note:- File which needs to be checkout is under subsite.
The following is my sample code:
//siteUrl = xxx.com
//subsite = acct
//relUrl = /acct/doclib/test.txt
using (ClientContext ctx = getContext(siteUrl))
{
var site = ctx.Web;
var file = site.GetFileByServerRelativeUrl(relUrl);
try
{
ctx.Load(file)
ctx.ExecuteQuery();
if (file.CheckOutType == CheckOutType.None)
{
file.CheckOut();
ctx.ExecuteQuery(); // this line is causing error
return true;
}
Hi I Have a MVC application that uploads a file to the server, all works fine on my local machine, as soon as I deploy to the server, it only works in Chrome and not in IE. The application reads a file and saves it on the server, I have added given. I have given the correct permissions to the Network Service to access the folder. Although when I run the application outside of the server in IE it fails with the above error. Please assist, any ideas? Please see code below.
[HttpPost]
public ActionResult Upload(HttpPostedFileBase file)
{
List<CleanSupplierClaim> supplierClaimsData = new List<CleanSupplierClaim>();
try
{
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var targetPath = Server.MapPath("~/upload");
file.SaveAs(Path.Combine(targetPath, fileName));
Here is my app pool config, set as the local system
And here is the folder permission setting.
I have allocated the correct permissions for the user reading file from users machine, which in my case is the Network Service. Although in IE it throws an exception 'Could not find a part of the path ''
How can I fix this issue, I have ran out of ideas. My IIS version is 8.5
What if Writing: var targetPath = Server.MapPath("/upload");
Server.MapPath("~") returns the physical path to the root of the application
Server.MapPath("/") returns the physical path to the root of the domain name (is not necessarily the same as the root of the application)
When I try to download a file from TFS version control SDK to my computer I receive an 'UnauthorizedAccessException' saying Access to the local path I'm trying to download to is denied. I included a stripped down version of the code I am using below.
var projectCollection = GetProjectCollection();
var versionControl = (VersionControlServer)projectCollection.GetService(typeof(VersionControlServer));
versionControl.DownloadFile('$/path to file', 'local path to download to');
Does anyone know how to resolve this issue?
I found the issue.
The second argument in DownloadFile() needs to be the file name it will be downloaded as and not the parent directory it will be placed in. I thought it just needed the directory name.
So instead of what I originally had
versionControl.DownloadFile("$/Readme.txt", "C:\\Temp");
it needs to be
versionControl.DownloadFile("$/Readme.txt", "C:\\Temp\\Readme.txt");
This is because the process does not have rights to the local path. Make sure the local path has the appropriate right set to the user that is running the process.