C# How to programmatically import files into Visual Studio project - c#

I have a file upload control that imports files into a directory on the server. I would like to import the file in the servers file system into my project programmatically using C#. It is an image that I would like to import so I can display that image to the website. An Alternative method maybe when I use the file upload control, to import directly into the websites folder. Can anyone help with this?
The code I have is as follows:-
Image1.ImageUrl = "~c:\users\fitzy\documents\visual studio\2013\Projects\PhotoGallery3\PhotoGallery3\photos\Appliance Insurance.JPG";
I want to be able to display the imported image using Image1.ImageUrl but the path on the server does not let me.

Since we do not know the error message, I am sharing 2 mostly possible reasons:
Your server user identity may not have a write permission to the upload folder. Check your upload folder if a newly uploaded file is located there or not.
Usage of an incorrect file path for uploaded images on the server, so your website cannot find them. You can see this case by 404 error message on your browser.

Related

asp.net upload file License file not found error

i have page to upload files with CuteWebUI.AjaxUploader
when i run this page in my local computer it work correctly
but when i run this page on the domain server it give this error
The error is clear, this program is commercial and its need a license to run.
You do not have include the AjaxUploader.lic on the bin directory with the CuteWebUI.AjaxUploader.dll file.

Open pdf file dynamically from toolstripmenu c# winform

i'm trying to open a pdf file from my winform application, while the pdf file is in the directory of the application. I want to pack this app latter so I can open them dynamically even if the app is installed in another machine. I'm using Process.Start(".\file.extension") but I'm getting the error: The system cannot find the file specified. I heard that I need to send it in System32 folder but when I pack it I have no idea how to send it there. Hope you understood and can come with a solution for this problem. Thanks in advance.
If the pdf file is inside the project itself, You can simply do this:
Your PDF File as seen from the solution explorer > Right Click > Properties
Copy to Output Directory > Copy Always
After this, each time you build your project or when you deploy it, The PDF file will always be included in the project output folder.
Try this...
string commandexec = string.format("{0}\{1}",AppDomain.CurrentDomain.BaseDirectory,filename);
Process.Start(commandexec);

Access to the path 'C:\\Program Files (x86)\\IIS Express\\Excel.xlsx' is denied

I'm working on a ASP.NET MVC 5 project. In this project I want user to download an Excel file using this code :
var workbook = new ExcelFile();
workbook.Save("Excel.xlsx");
But when I enter the URL to download the Excel file. I get the exception :
Access to the path 'C:\Program Files (x86)\IIS Express\Excel.xlsx'
is denied.
How can I modify my code so that user can download the Excel file wherever he wants? Instead of IIS Express folder. Thanks.
In my opinion you have two options.
1: Chage the permission of the IIS folder/directory.
2: Save the file to Response an let the user choose per SaveFileDialog(try this: Downloading Excel File)
I know its too late, but in order to access the folder you should run visual studio as admin.

File or directory not found in IIS7 in asp.net?

I have published my project in IIS7. When I browse particular .ashx file in the browser, I got File or directory not found issue.
When I browse the same .ashx file in my local server file details have been shown. But in my local PC file details have not been shown. How to resolve that isse?
I would suggest you few steps:
Make sure you have added the file into your .Net project. The file is probably missing in your project.
Also double check the spelling. Sometimes is just a typo.
Type the path manually in your browser and see where it is looking for the file.
These options might be enough.

c# .net - Question about multiple Projects under same solution in Visual Studio 2010

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.

Categories