コンテンツ/ギャラリーフォルダにギャラリー画像をアップロードし、コンテンツ/ファイルフォルダにダウンロード可能なファイルをアップロードするには、fileupload.csを再利用できるようにする必要があります。私は解決策がファイルパス文字列を何とか動的にすることになると考えています。ギャラリーとファイルには異なるコントローラ、モデル、ビューがあります。以下はfileupload.csコードがあるファイルアップロードのFilePathを制御するMVC3
public static class FileUpload
{
public static char DirSeparator = System.IO.Path.DirectorySeparatorChar;
public static string FilesPath = "Content" + DirSeparator + "Files" + DirSeparator;
public static string UploadFile(HttpPostedFileBase file)
{
// Check if we have a file
if (null == file) return "";
// Make sure the file has content
if (!(file.ContentLength > 0)) return "";
string fileName = file.FileName;
string fileExt = Path.GetExtension(file.FileName);
// Make sure we were able to determine a proper
// extension
if (null == fileExt) return "";
// Check if the directory we are saving to exists
if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory+FilesPath))
{
// If it doesn't exist, create the directory
Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory+FilesPath);
}
// Set our full path for saving
string path = FilesPath + DirSeparator + fileName;
// Save our file
//file.SaveAs(Path.GetFullPath(path));
file.SaveAs(Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory +path));
// Return the filename
return fileName;
}
public static void DeleteFile(string fileName)
{
// Don't do anything if there is no name
if (fileName.Length == 0) return;
// Set our full path for deleting
string path = FilesPath + DirSeparator + fileName;
// Check if our file exists
if (File.Exists(Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory+path)))
{
// Delete our file
File.Delete(Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory+path));
}
}
}
あなたはこれまでに何を試しましたか?何がうまくいかなかったのですか? 90%であなたの要件を満たし、他の誰かが10%をやるように求めるインターネット上のどこかのソースコードを表示するのは、Stack Overflowのためのものではありません。 'あなたは、ファイルパス文字列を何らかの形で動的にするという解決策が得られると信じていると言っています。これは素晴らしいことです。この最初のアイデアをより正確にいかに試しましたか? –