简体   繁体   English

C# 如何以编程方式将文件导入 Visual Studio 项目

[英]C# How to programmatically import files into Visual Studio project

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#.我想使用 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";我的代码如下:- 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.我希望能够使用 Image1.ImageUrl 显示导入的图像,但服务器上的路径不允许我。

Since we do not know the error message, I am sharing 2 mostly possible reasons:由于我们不知道错误消息,我分享两个最可能的原因:

  1. 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.检查您的上传文件夹是否有新上传的文件。
  2. 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.您可以通过浏览器上的 404 错误消息看到这种情况。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# 如何使用 Visual Studio 2019 以编程方式启动项目实例 - C# how to programmatically launch an instance of a project with Visual Studio 2019 如何在 Visual Studio、C# 项目的部署中包含文件和文件夹? - How to include files and folders in the deployment of a visual studio, C# project? 如何将ObjectListView导入Visual Studio C#? - How to import ObjectListView into Visual Studio C#? 如何使用 c# 在 Visual Studio 2010 中以编程方式将现有项目添加到当前解决方案 - How to add an existing project to a current solution programmatically in visual studio 2010 using c# 如何根据 Visual Studio 中的文件名以编程方式更改 C# .cs 文件? - How to programmatically make changes to C# .cs files based on the file name in Visual Studio? 无法将Visual Studio制作的C ++ DLL导入Windows上的Visual Studio C#项目 - Unable to Import a Visual Studio made C++ DLL into a Visual Studio C# Project on Windows 以编程方式升级Visual Studio解决方案和项目文件 - Upgrade Visual Studio solution and project files programmatically 如何从c#中以编程方式编译Visual c ++项目? - how compile Visual c++ project programmatically from c#? 在项目外使用 Visual Studio 打开 c# 文件没有给出任何建议 - opening c# files with visual studio outside of project gives no suggestions 在C#中定义Visual Studio Project文件的相对路径 - Defining relative paths for my Visual Studio Project files in c#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM