C
C#4mo ago
Bamblobski

✅ Error: The remote server returned an error: (403)

i try to download files from sharepoint and after that it gives me an exeption i know the string are empty but just privat my code:
using System;
using System.Data;

public class Program
{
public static void Main(string[] args)
{
try
{
string filename = "";
string sharepointUrl = "";
string sheetName = "";
string connectionString = "";
string tableName = "";
string username = "";
string password = "";

Console.WriteLine("Lade Datei von SharePoint herunter");
SharePointDownloader.DownloadFile(sharepointUrl, filename, username, password);

Console.WriteLine("Lese Excel-Datei herunter");
DataTable dataTable = ExcelReader.ReadExcelFile(filename, sheetName);

dataTable.Columns.Add("Dateiname", typeof(string));
foreach (DataRow row in dataTable.Rows)
{
row["Dateiname"] = filename;
}

Console.WriteLine("Importiere Daten in die SQL-Datenbank");
SqlImporter.ImportToSqlDatabase(dataTable, connectionString, tableName);

Console.WriteLine("Führe gespeicherte Prozedur aus");
SqlImporter.ExecuteStoredProcedure(connectionString, "sp_async_SP_starter_Trigger", "Import VKS Strom", "ABRECHNUNG", "sp_zev_upsertNBK", filename);

Console.WriteLine("Daten erfolgreich in die SQL-Datenbank importiert");
}
catch (Exception ex)
{
Console.WriteLine("Fehler: " + ex.Message);
}
finally
{
Console.WriteLine("Drücken Sie eine beliebige Taste, um das Programm zu beenden");
Console.ReadKey();
}
}
}
using System;
using System.Data;

public class Program
{
public static void Main(string[] args)
{
try
{
string filename = "";
string sharepointUrl = "";
string sheetName = "";
string connectionString = "";
string tableName = "";
string username = "";
string password = "";

Console.WriteLine("Lade Datei von SharePoint herunter");
SharePointDownloader.DownloadFile(sharepointUrl, filename, username, password);

Console.WriteLine("Lese Excel-Datei herunter");
DataTable dataTable = ExcelReader.ReadExcelFile(filename, sheetName);

dataTable.Columns.Add("Dateiname", typeof(string));
foreach (DataRow row in dataTable.Rows)
{
row["Dateiname"] = filename;
}

Console.WriteLine("Importiere Daten in die SQL-Datenbank");
SqlImporter.ImportToSqlDatabase(dataTable, connectionString, tableName);

Console.WriteLine("Führe gespeicherte Prozedur aus");
SqlImporter.ExecuteStoredProcedure(connectionString, "sp_async_SP_starter_Trigger", "Import VKS Strom", "ABRECHNUNG", "sp_zev_upsertNBK", filename);

Console.WriteLine("Daten erfolgreich in die SQL-Datenbank importiert");
}
catch (Exception ex)
{
Console.WriteLine("Fehler: " + ex.Message);
}
finally
{
Console.WriteLine("Drücken Sie eine beliebige Taste, um das Programm zu beenden");
Console.ReadKey();
}
}
}
No description
67 Replies
Bamblobski
Bamblobski4mo ago
using System;
using System.Net;
using System.IO;

public class SharePointDownloader
{
public static void DownloadFile(string sharepointUrl, string filename, string username, string password)
{
using (var client = new WebClient())
{
client.Credentials = new NetworkCredential(username, password);
client.DownloadFile(sharepointUrl,filename);
}
}
}
using System;
using System.Net;
using System.IO;

public class SharePointDownloader
{
public static void DownloadFile(string sharepointUrl, string filename, string username, string password)
{
using (var client = new WebClient())
{
client.Credentials = new NetworkCredential(username, password);
client.DownloadFile(sharepointUrl,filename);
}
}
}
Jimmacle
Jimmacle4mo ago
MDN Web Docs
403 Forbidden - HTTP | MDN
The HTTP 403 Forbidden response status code indicates that the server understands the request but refuses to authorize it.
Pobiega
Pobiega4mo ago
WebClient :when: HttpClient is your friend, webclient is obsolete
Bamblobski
Bamblobski4mo ago
thank u
Pobiega
Pobiega4mo ago
but yeah, check what Jimmacle posted. 403 means the server said you are not allowed to access this resource, probably due to wrong access levels/tenant information
Jimmacle
Jimmacle4mo ago
i mean, the credentials being blank will do that you need to test the method with valid arguments
Bamblobski
Bamblobski4mo ago
they are just private in discord, i did test it with a local file, and it said something with invalid to INSERT, first i try to get a connection
Jimmacle
Jimmacle4mo ago
that sounds like an entirely different error than the one you made the post about
Bamblobski
Bamblobski4mo ago
yeah, but i changed the path to sharepoint, i just wanted to see if my code does work with local files i will try with HttpClient now
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
why is everyone hating it xD
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
yeah and oh haha
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
xD HAHAHAH
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
i already changed it
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
btw my code was wrong, i should have used graph api
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
yes
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
MSSQL
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
ehhh
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
xD
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
1 sec
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
im not sure if its azur to be on honest, let me look things up
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
yeah i wanna find the things that u asked
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
no but i was speaking to the programmer and she said, i should wait with the task (20min ago), we already have something similar but not with download, but with upload, and it gives us problems bc it says that the files are to long
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX4mo ago
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
from my project? or the similar one with the upload where its working
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
i dont have csproj
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
yes
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
No description
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
oh
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
yeah azure identity isnt on the latest version i think
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
yeah i dont have this i have ProjectReference
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
yes
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
it was bc my pw and name was wrong, i didnt know that, my programmer showed me that, and said dont do string pw= "", do graph api connection like in the other programm thats the other project my programm is complet new
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
sharepoint
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
no
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
all good my stuff was also confusing also im trying it with local files now still doesnt work
Bamblobski
Bamblobski4mo ago
'The specified ColumnMapping does not match any column in the source or target.'
No description
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Bamblobski
Bamblobski4mo ago
im on it
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX4mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Bamblobski
Bamblobski4mo ago
sure still thanks for ur time
Want results from more Discord servers?
Add your server